Consider this example:
class A
{
void foo();
public:
void bar();
};
template <class> class B
{
B()
{
A a;
a.foo(); // 1
A::bar(); // 2
a.bar(1); // 3
}
};
Note B
is never instantiated.
clang++
reports all three marked lines as erroneous. g++
(4.8.3) accepts lines 1
and 2
and only reports line 3
.
If B
is instantiated, g++
happily reports all three lines as erroneous.
Is this a g++
bug? One would think so. A
is not a dependent name and its members should be checked normally at template definition time. Are there nuances I don't see?
Those pre-instantiation messages aren't enforced by the standard and are up to the compiler
n3337 § 14.6 - 8
No diagnostic shall be issued for a template definition for which a valid specialization can be generated. If no valid specialization can be generated for a template definition, and that template is not instantiated, the template definition is ill-formed, no diagnostic required.
emphasis mine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With