[Bug c++/103426] New: Acceptance of invalid template specialization in a namespace not enclosing the specialized template
fchelnokov at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Nov 25 12:23:12 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103426
Bug ID: 103426
Summary: Acceptance of invalid template specialization in a
namespace not enclosing the specialized template
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fchelnokov at gmail dot com
Target Milestone: ---
The code as follows is invalid:
```
template<typename T>
struct S {
static int x;
};
namespace {
template<> int S<int>::x = 0;
}
```
because an explicit specialization shall be declared in a namespace enclosing
the specialized template. Clang rejects it, but not GCC. Demo:
https://gcc.godbolt.org/z/74oxofsaf
Related discussion: https://stackoverflow.com/q/30400814/7325599
More information about the Gcc-bugs
mailing list