[Bug c++/42018] Accepts definition for non-anonymous specialized template method within anonymous namespace
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42018 Jonathan Wakely redi at gcc dot gnu.org changed: What|Removed |Added Keywords||accepts-invalid Status|UNCONFIRMED |NEW Last reconfirmed||2010.10.01 11:52:43 Ever Confirmed|0 |1 Known to fail||4.1.2, 4.3.4, 4.4.3, 4.5.1, ||4.6.0 --- Comment #3 from Jonathan Wakely redi at gcc dot gnu.org 2010-10-01 11:52:43 UTC --- Oops, I've just realised I pasted the wrong code in comment 2, I meant to say that this fails: templatetypename void foo(void); namespace { template void fooint(void) { return; } } template void fooint(void); int main(int, char **) { fooint(); } i.e. if the invalid specialization comes before the valid specialization, it's rejected. But in the original example, where the invalid specialization comes later, it's incorrectly accepted. The same error should be given in both cases: the specialization in the anon namespace does not match any primary template declaration.
[Bug c++/42018] Accepts definition for non-anonymous specialized template method within anonymous namespace
--- Comment #1 from redi at gcc dot gnu dot org 2009-11-12 13:24 --- It should fail to compile because you are specializing a template which was never declared, not because it is ambiguous. namespace { template void fooint(void) { return; } } That is a specialization, but there is no matching primary template. This fails due to ambiguous overloads: templatetypename void foo(void); template void fooint(void); namespace { templateclass void foo(void) { return; } } -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42018
[Bug c++/42018] Accepts definition for non-anonymous specialized template method within anonymous namespace
--- Comment #2 from redi at gcc dot gnu dot org 2009-11-12 13:28 --- This fails: templatetypename void foo(void); template void fooint(void); namespace { template void fooint(void) { return; } } int main(int, char **) { fooint(); } ttt.cc:6: error: specialization of 'templateclass void foo()' in different namespace ttt.cc:2: error: from definition of 'templateclass void foo()' But if a valid specialization already exists, the one in the anon namespace is not rejected. That's a bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42018