AutosarC++17_10-M14.7.3

All partial and explicit specializations for a template shall be declared in the same file as the declaration of their primary template

Required inputs: IR

Template specializations should be declared in the same file as the primary template declaration to keep related code together and avoid confusion about which specialization applies. When specializations are scattered across multiple files, it becomes difficult to understand which specialization will be used and increases the risk of accidentally creating duplicate specializations.
Bad code (specialization in different file):
// template.h
template<typename T>
class Widget { /* definition */ };

// widget_int.cpp
template<>  // ERROR: specialization in different file
class Widget<int> {
    void process();
};
Good code (specialization in same file as primary):
// template.h
template<typename T>
class Widget { /* definition */ };

template<>     // OK: specialization in same file as primary
class Widget<int> { /* specialized for int */ };

// other.cpp
#include "template.h"  // Includes both primary and specialization
Exception (template only declared in header):
// template.h
template<typename T>
class Widget;  // Forward declaration only

// template.cpp
template<typename T>
class Widget { /* definition in .cpp */ };

template<>
class Widget<int> { /* OK: may be in different file */ };

Note

For legal reasons, this rule’s description is not part of the public documentation.