Debian Codegraph @

gcc/testsuite/g++.dg/tc1/dr147.C

raw
1 // { dg-do compile }
2 // Origin: Giovanni Bajo <giovannibajo at gcc dot gnu dot org>
3 // DR147: Naming the constructor (PR 11764)
4
5 namespace N1 {
6
7 struct A { A(); void f(); };
8 struct B: public A { B(); };
9
10 A::A() { }
11 B::B() { }
12
13 B::A ba;
14 A::A a; // { dg-error "constructor" "the injected-class-name can never be found through qualified lookup" }
15
16 void A::f()
17 {
18 A::A(); // { dg-message "::A" "c++/42415" }
19 }
20
21 void f()
22 {
23 A::A a; // { dg-error "constructor" "constructor" }
24 }
25 }
26
27 namespace N2 {
28
29 // This is nasty: if we allowed the injected-class-name to be looked as a
30 // qualified type, then the following code would be well-formed. Basically
31 // the last line is defining the static member (with redundant parenthesis).
32 // Instead, it should be rejected as a malformed constructor declaration.
33
34 template <class T> struct A {
35 template <class T2> A(T2);
36 static A x;
37 };
38 template<> template <> A<char>::A<char>(char);
39 template<> A<int>::A<int>(A<int>::x); // { dg-error "" "this is an invalid declaration of the constructor" }
40
41 }
42
43 // But DR 318 says that in situations where a type is syntactically
44 // required, lookup finds it.
45
46 struct C
47 {
48 C();
49 typedef int T;
50 };
51 struct C::C c;
52 C::C::T t;
53 struct D: C::C
54 {
55 D(): C::C() { }
56 };
57
58 // And if lookup doesn't find the injected-class-name, we aren't naming the
59 // constructor (c++/44401).
60
61 struct E
62 {
63 int E;
64 };
65
66 int E::*p = &E::E;