diff options
author | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-01-09 13:47:42 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-01-09 13:47:42 +0000 |
commit | b4a5df67f1382a33f4535eb1b10600ca52d294d3 (patch) | |
tree | d4571b191c2cfc0f5045bd27b54f8a48e70787a8 /gcc/testsuite/g++.dg/lookup | |
download | gcc-tarball-b4a5df67f1382a33f4535eb1b10600ca52d294d3.tar.gz |
Tarball conversion
Diffstat (limited to 'gcc/testsuite/g++.dg/lookup')
176 files changed, 3009 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/lookup/ambig1.C b/gcc/testsuite/g++.dg/lookup/ambig1.C new file mode 100644 index 0000000000..1cf9ab4f0a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ambig1.C @@ -0,0 +1,17 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Aug 2004 <nathan@codesourcery.com> +// Origin: Wolfgang Bangerth <bangerth@dealii.org> + +// Bug 16889:Undetected ambiguity. + +struct B { + int f(); // { dg-error "int B::f" "" } +}; + +struct B1 : virtual B {}; +struct B2 : B {}; +struct BB : B1, B2 {}; + +int i = BB().f(); // { dg-error "ambiguous" "" } diff --git a/gcc/testsuite/g++.dg/lookup/ambig2.C b/gcc/testsuite/g++.dg/lookup/ambig2.C new file mode 100644 index 0000000000..4d423d1706 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ambig2.C @@ -0,0 +1,17 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Aug 2004 <nathan@codesourcery.com> +// Origin: Wolfgang Bangerth <bangerth@dealii.org> + +// Bug 16889:Undetected ambiguity. + +struct B { + int i; // { dg-error "int B::i" "" } +}; + +struct B1 : virtual B {}; +struct B2 : B {}; +struct BB : B1, B2 {}; + +int i = BB().i; // { dg-error "ambiguous" "" } diff --git a/gcc/testsuite/g++.dg/lookup/ambig3.C b/gcc/testsuite/g++.dg/lookup/ambig3.C new file mode 100644 index 0000000000..7a0a8377a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ambig3.C @@ -0,0 +1,18 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 23 Sep 2004 <nathan@codesourcery.com> +// Origin: Wolfgang Bangerth <bangerth@dealii.org> + +// Follow on from Bug 16889:Undetected ambiguity. + +struct B { + int f(); // { dg-error "int B::f" "" } +}; + +struct B1 : virtual B {}; +struct B2 : B {}; +struct B2_2 : B2 {}; +struct BB : B1, B2_2 {}; + +int i = BB().f(); // { dg-error "ambiguous" "" } diff --git a/gcc/testsuite/g++.dg/lookup/ambig4.C b/gcc/testsuite/g++.dg/lookup/ambig4.C new file mode 100644 index 0000000000..3a74f7d1c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ambig4.C @@ -0,0 +1,14 @@ +// PR c++/13377 +// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de> +// { dg-do compile } + +namespace N +{ + int i; // { dg-error "i" } +} + +int i; // { dg-error "i" } + +using namespace N; + +void foo() { i; } // { dg-error "ambiguous" } diff --git a/gcc/testsuite/g++.dg/lookup/ambig5.C b/gcc/testsuite/g++.dg/lookup/ambig5.C new file mode 100644 index 0000000000..cebec27791 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ambig5.C @@ -0,0 +1,13 @@ +// PR c++/13377 +// Origin: Boris Kolpackov <boris@kolpackov.net> +// { dg-do compile } + +namespace N +{ + namespace M {} // { dg-error "M" } +} + +namespace M {} // { dg-error "M" } + +using namespace N; +using namespace M; // { dg-error "namespace-name|ambiguous" } diff --git a/gcc/testsuite/g++.dg/lookup/anon1.C b/gcc/testsuite/g++.dg/lookup/anon1.C new file mode 100644 index 0000000000..e4db50d946 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/anon1.C @@ -0,0 +1,47 @@ +// PR c++/2039 +// Test that a scoped reference to a member of an anonymous union member of +// a base class works properly. + +// { dg-do run } + +struct A +{ + long ia1; + union + { + long ia2; + }; +}; + +struct B : public A +{ + void f1(); + void f2(); +}; + +void B::f1() +{ + ia1 = 11; + ia2 = 22; +} + +void B::f2() +{ + ia1 = 33; + A::ia2 = 44; // <<< !!!???? +} + +int main() +{ + B x; + + x.f1(); + if (x.ia1 != 11 || x.ia2 != 22) + return 1; + + x.f2(); + if (x.ia1 != 33 || x.ia2 != 44) + return 1; + + return 0; +} diff --git a/gcc/testsuite/g++.dg/lookup/anon2.C b/gcc/testsuite/g++.dg/lookup/anon2.C new file mode 100644 index 0000000000..d556ba0034 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/anon2.C @@ -0,0 +1,9 @@ +// { dg-do compile } +// { dg-options "" } + +// Make sure we issue a diagnostic if a type with no linkage is used +// to declare a a variable that has linkage. + +struct { int i; } a; // { dg-warning "anonymous type" } + +void foo() { a.i; } diff --git a/gcc/testsuite/g++.dg/lookup/anon3.C b/gcc/testsuite/g++.dg/lookup/anon3.C new file mode 100644 index 0000000000..2523e0a7dd --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/anon3.C @@ -0,0 +1,11 @@ +// Test that anonymous unions work with explicit scope. + +static union +{ + int i; +}; + +int main() +{ + return ::i; +} diff --git a/gcc/testsuite/g++.dg/lookup/anon4.C b/gcc/testsuite/g++.dg/lookup/anon4.C new file mode 100644 index 0000000000..40c4ab40a5 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/anon4.C @@ -0,0 +1,9 @@ +static union { + int i; +}; + +int *ip; + +void g() { + ip = &i; +} diff --git a/gcc/testsuite/g++.dg/lookup/anon5.C b/gcc/testsuite/g++.dg/lookup/anon5.C new file mode 100644 index 0000000000..c3d36c20f5 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/anon5.C @@ -0,0 +1,21 @@ +// PR c++/28409 +// shouldIbevisible should be emitted because it's an extern "C" decl with +// external linkage, even though it's in the anonymous namespace. + +namespace +{ + extern "C" int shouldIbevisible() + { + return 0; + } +} + +namespace t +{ + extern "C" int shouldIbevisible(void); +} + +int main(void) +{ + return t::shouldIbevisible(); +} diff --git a/gcc/testsuite/g++.dg/lookup/anon6.C b/gcc/testsuite/g++.dg/lookup/anon6.C new file mode 100644 index 0000000000..09fa7f8f3b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/anon6.C @@ -0,0 +1,11 @@ +extern int v1; // { dg-error "declared" } +static union { int v1; }; // { dg-error "redeclaration" } + +static union { int v2; }; // { dg-error "declared" } +extern int v2; // { dg-error "redeclaration" } + +int v3; // { dg-error "declared" } +static union { int v3; }; // { dg-error "redeclaration" } + +static union { int v4; }; // { dg-error "declared" } +static union { int v4; }; // { dg-error "redeclaration" } diff --git a/gcc/testsuite/g++.dg/lookup/anon7.C b/gcc/testsuite/g++.dg/lookup/anon7.C new file mode 100644 index 0000000000..79cad0acb9 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/anon7.C @@ -0,0 +1,26 @@ +// PR c++/39560 +// { dg-options -Wunused } + +struct X { }; + +class Z { +public: + X* cc(int c); +}; + +class F { +public: + typedef X* (Z::*MethO)(int); + typedef X* (F::*MethF)(int); + template<MethO m> + X* xwrapper(int i) { + union { + Z *z; + F *f; + }; // { dg-bogus "unused" } + f = this; + return ((z->*m)(i)); + } +}; + +F::MethF meth = &F::xwrapper<&Z::cc>; diff --git a/gcc/testsuite/g++.dg/lookup/builtin1.C b/gcc/testsuite/g++.dg/lookup/builtin1.C new file mode 100644 index 0000000000..5f25f28896 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/builtin1.C @@ -0,0 +1,12 @@ +// PR c++/19367 +// { dg-do link } + +void abort (void) { throw 3; } + +namespace std { using ::abort; } + +int main () +{ + using std::abort; + abort(); +} diff --git a/gcc/testsuite/g++.dg/lookup/builtin2.C b/gcc/testsuite/g++.dg/lookup/builtin2.C new file mode 100644 index 0000000000..be0a6f65d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/builtin2.C @@ -0,0 +1,19 @@ +/* { dg-do compile } */ + +/* PR c++/21087 */ + +/* We used to overload the template function with the built-in + declaration, instead of replacing it as we should, and then barf at + the using decl because of a test that none of the overload set + members were anticipated built-ins. */ + +extern "C" signed int toupper(signed int __c) throw(); +namespace std +{ + template< typename a > a toupper(a,int){} + using ::toupper; +} + +int f () { + std::toupper((signed int)'a'); +} diff --git a/gcc/testsuite/g++.dg/lookup/builtin3.C b/gcc/testsuite/g++.dg/lookup/builtin3.C new file mode 100644 index 0000000000..3a29d87831 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/builtin3.C @@ -0,0 +1,15 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> +// { dg-do compile } + +// PR 31749: ICE with redeclaration of builtin + +namespace std +{ + union abort; +} + +void abort(); + +using std::abort; diff --git a/gcc/testsuite/g++.dg/lookup/builtin4.C b/gcc/testsuite/g++.dg/lookup/builtin4.C new file mode 100644 index 0000000000..b1785dcc7f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/builtin4.C @@ -0,0 +1,15 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> +// { dg-do compile } + +// PR 31749: ICE with redeclaration of builtin + +namespace std +{ + union abort; +} + +union abort; + +using std::abort; // { dg-error "" } diff --git a/gcc/testsuite/g++.dg/lookup/builtin5.C b/gcc/testsuite/g++.dg/lookup/builtin5.C new file mode 100644 index 0000000000..1bd67dce5a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/builtin5.C @@ -0,0 +1,16 @@ +// PR c++/37276 + +// { dg-final { scan-assembler "_ZSt5atanhd" } } + +namespace std +{ + inline double + atanh(double __x) + { return __builtin_atanh(__x); } +} + +int main() +{ + std::atanh(.3); + return 0; +} diff --git a/gcc/testsuite/g++.dg/lookup/class-member-1.C b/gcc/testsuite/g++.dg/lookup/class-member-1.C new file mode 100644 index 0000000000..37d40b4cc3 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/class-member-1.C @@ -0,0 +1,11 @@ +// Copyright (C) 2002 Free Software Foundation +// Origin: PR/7621, Vaclav.Haisman@logout.sh.cvut.cz +// Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> + +struct A { }; + +int main() +{ + A a; + a.i = 9; // { dg-error "no member" "" } +} diff --git a/gcc/testsuite/g++.dg/lookup/class-member-2.C b/gcc/testsuite/g++.dg/lookup/class-member-2.C new file mode 100644 index 0000000000..8e4dbe72d7 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/class-member-2.C @@ -0,0 +1,7 @@ +template <typename T> struct A +{ + void foo () const {} + char A; +}; + +void bar() { A<void>().foo(); } diff --git a/gcc/testsuite/g++.dg/lookup/conv-1.C b/gcc/testsuite/g++.dg/lookup/conv-1.C new file mode 100644 index 0000000000..0c4393e8a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/conv-1.C @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 21 Jul 2004 <nathan@codesourcery.com> + +// Failed to spot ambiguous conversion + +struct A1 +{ + operator int () const; // { dg-message "A1::operator" "" } +}; + +struct A2 +{ + operator int () const; // { dg-message "A2::operator" "" } +}; + +struct B : A1, A2 +{ +}; + +int Foo (B const &b) +{ + return b; // { dg-error "ambiguous" "" } + // { dg-message "candidate" "candidate note" { target *-*-* } 24 } +} + diff --git a/gcc/testsuite/g++.dg/lookup/conv-2.C b/gcc/testsuite/g++.dg/lookup/conv-2.C new file mode 100644 index 0000000000..6a087e1839 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/conv-2.C @@ -0,0 +1,22 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 21 Jul 2004 <nathan@codesourcery.com> + +// { dg-final { scan-assembler "_ZNK2A1cviEv" } } + +struct A1 +{ + operator int () const; // this one +}; + +struct A2 : A1 +{ + template<typename T> operator T () const; +}; + +int Foo (A2 const &b) +{ + return b; +} + diff --git a/gcc/testsuite/g++.dg/lookup/conv-3.C b/gcc/testsuite/g++.dg/lookup/conv-3.C new file mode 100644 index 0000000000..14b1446a2b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/conv-3.C @@ -0,0 +1,22 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 21 Jul 2004 <nathan@codesourcery.com> + +// { dg-final { scan-assembler "_ZNK2A1IiEcviEv" } } + +template <typename T> struct A1 +{ + operator T () const; // this one +}; + +struct A2 : A1<int> +{ + template<typename T> operator T () const; +}; + +int Foo (A2 const &b) +{ + return b; +} + diff --git a/gcc/testsuite/g++.dg/lookup/conv-4.C b/gcc/testsuite/g++.dg/lookup/conv-4.C new file mode 100644 index 0000000000..cd85b2ad33 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/conv-4.C @@ -0,0 +1,35 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 21 Jul 2004 <nathan@codesourcery.com> + +// { dg-final { scan-assembler "_ZNK1AcviEv" } } +// { dg-final { scan-assembler-not "_ZNK1VcviEv" } } + +struct V +{ + operator int () const; +}; + +struct A : virtual V +{ + operator int () const; // this one +}; + +struct B1 : A, virtual V +{ +}; + +struct B2 : virtual V, A +{ +}; + + +int Foo (B1 const &b) +{ + return b; +} +int Foo (B2 const &b) +{ + return b; +} diff --git a/gcc/testsuite/g++.dg/lookup/conv-5.C b/gcc/testsuite/g++.dg/lookup/conv-5.C new file mode 100644 index 0000000000..f8df710920 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/conv-5.C @@ -0,0 +1,15 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 17 Dec 2004 <nathan@codesourcery.com> + +// PR 18721. bogus error +// Origin: Mikael Kilpel?inen <belz@kolumbus.fi> + +struct A { + template<typename T> + operator T() const; + + operator float() const; +}; + diff --git a/gcc/testsuite/g++.dg/lookup/crash1.C b/gcc/testsuite/g++.dg/lookup/crash1.C new file mode 100644 index 0000000000..cd90685c70 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/crash1.C @@ -0,0 +1,31 @@ +// { dg-do compile } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 25 Aug 2003 <nathan@codesourcery.com> +// Origin pr 11871 Dirk Mueller <mueller@kde.org> + +// PR c++/11871 Regression + +namespace std +{ + class A + { + public: + enum result + { + ok + }; + }; + + template<typename T> class B : public A + { + public: + typedef A::result result; + }; +} + +int main() +{ + for(float result = 1.0;;); +} + diff --git a/gcc/testsuite/g++.dg/lookup/crash2.C b/gcc/testsuite/g++.dg/lookup/crash2.C new file mode 100644 index 0000000000..82735245f4 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/crash2.C @@ -0,0 +1,20 @@ +// PR c++/14086 + +struct ClassA +{ + ClassA(); +}; + +struct ClassB +{ + enum Enum {ClassB}; // { dg-error "" } + ClassA key; + + ClassB(); + virtual ~ClassB(); +}; + + +ClassB::ClassB() +{ +} diff --git a/gcc/testsuite/g++.dg/lookup/crash3.C b/gcc/testsuite/g++.dg/lookup/crash3.C new file mode 100644 index 0000000000..24a3360ba3 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/crash3.C @@ -0,0 +1,15 @@ +// { dg-do compile } +// Contributed by Wolfgang Wieser <wwieser at gmx dot de> +// PR c++/15967: ICE with ambiguous operator new + +typedef __SIZE_TYPE__ size_t; + +struct A { void *operator new(size_t s){} }; // { dg-error "operator new" } +struct B { void *operator new(size_t s){} }; // { dg-error "operator new" } + +struct C : A,B {}; + +int crash() +{ + C *c=new C(); // { dg-error "ambiguous" } +} diff --git a/gcc/testsuite/g++.dg/lookup/crash4.C b/gcc/testsuite/g++.dg/lookup/crash4.C new file mode 100644 index 0000000000..65686512a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/crash4.C @@ -0,0 +1,18 @@ +// { dg-do compile } +// +// PR 3761 + +struct A {}; + +struct B {}; + +template <class T> +struct Foo : A, B +{ + void func(void); + + struct Nested + { + friend void Foo::func(void); + }; +}; diff --git a/gcc/testsuite/g++.dg/lookup/crash5.C b/gcc/testsuite/g++.dg/lookup/crash5.C new file mode 100644 index 0000000000..6584ee6450 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/crash5.C @@ -0,0 +1,9 @@ +// { dg-do compile } +// +// PR 17618 + +void foo() +{ + p; // { dg-error "not declared" } + (void*) p; +} diff --git a/gcc/testsuite/g++.dg/lookup/crash6.C b/gcc/testsuite/g++.dg/lookup/crash6.C new file mode 100644 index 0000000000..0e49324bf2 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/crash6.C @@ -0,0 +1,8 @@ +// { dg-do compile } + +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> + +// PR c++/18652: ICE redeclaring variable as template. + +int A; // { dg-error "previous declaration" } +template<int> struct A; // { dg-error "different kind of symbol" } diff --git a/gcc/testsuite/g++.dg/lookup/crash7.C b/gcc/testsuite/g++.dg/lookup/crash7.C new file mode 100644 index 0000000000..a3389a01a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/crash7.C @@ -0,0 +1,9 @@ +// PR c++/35323 +// { dg-options "" } + +void foo(int); + +void bar() +{ + foo(1r); // { dg-error "not supported" } +} diff --git a/gcc/testsuite/g++.dg/lookup/decl1.C b/gcc/testsuite/g++.dg/lookup/decl1.C new file mode 100644 index 0000000000..d9af65604c --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/decl1.C @@ -0,0 +1,32 @@ +// { dg-do compile } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com> + +// PR 8702. Failure to match templates. + +template <typename X> struct C1{}; + +template <typename X> +struct C2 { + template<typename Y> operator C1<Y>(); + template<typename Y> operator C2<Y>(); +}; + +template<typename X> template<typename Y> +C2<X>::operator C1<Y>() +{ + return C1<Y>(); +} + +struct A +{ + operator int (); // { dg-error "operator" "" } + operator float (); // { dg-error "operator" "" } + operator float () const; // { dg-error "operator" "" } + template <typename T> operator T * (); // { dg-error "candidates" "" } +}; + +A::operator short () { // { dg-error "prototype for" "" } + return 0; +} diff --git a/gcc/testsuite/g++.dg/lookup/decl2.C b/gcc/testsuite/g++.dg/lookup/decl2.C new file mode 100644 index 0000000000..75ce0967a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/decl2.C @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com> +// Source Martin Buchholz martin@xemacs.org + +// PR 9053. Failed to consider templates that are disambiguated by +// return type. + +template <typename T> class bar; +template <> struct bar<const char*> { typedef void type; }; +template <typename T> class qux; +template <> struct qux<int> { typedef void type; }; + +template <typename T> +typename bar<T>::type foo (T t) { } + +template <typename T> +typename qux<T>::type foo (T t) { } + + +int +main (int argc, char *argv[]) +{ + foo ("foo"); + foo (7); +} diff --git a/gcc/testsuite/g++.dg/lookup/delete1.C b/gcc/testsuite/g++.dg/lookup/delete1.C new file mode 100644 index 0000000000..beaed209dc --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/delete1.C @@ -0,0 +1,16 @@ +// PR c++/2136 +// Test that overloaded op new and delete don't prevent us from using the +// global versions with an explicit scope. + +#include <stddef.h> + +struct A { + void *operator new (size_t, float); + void operator delete (void *, float); +}; + +int main () +{ + A *p = ::new A; + ::delete p; +} diff --git a/gcc/testsuite/g++.dg/lookup/disamb1.C b/gcc/testsuite/g++.dg/lookup/disamb1.C new file mode 100644 index 0000000000..7585a32e1e --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/disamb1.C @@ -0,0 +1,15 @@ +// PR c++/525 +// Bug: With -pedantic, we weren't converting this to B1* for the call. + +struct A +{ + void f(); +}; + +struct B1: public A {}; +struct B2: public A {}; + +struct C: public B1, public B2 +{ + void g() { B1::f(); } +}; diff --git a/gcc/testsuite/g++.dg/lookup/duperr1.C b/gcc/testsuite/g++.dg/lookup/duperr1.C new file mode 100644 index 0000000000..cfb348d49c --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/duperr1.C @@ -0,0 +1,5 @@ +// PR c++/29048 + +class A { int i; }; // { dg-bogus "is private.*is private" } +// { dg-error "is private" "" { target *-*-* } 3 } +class B:public A { B() { A::i=0; } }; // { dg-error "within this context" } diff --git a/gcc/testsuite/g++.dg/lookup/enum1.C b/gcc/testsuite/g++.dg/lookup/enum1.C new file mode 100644 index 0000000000..9422814e27 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/enum1.C @@ -0,0 +1,5 @@ +// PR c++/14476 + +struct tree_common { + enum tree_code code : 8; // { dg-error "" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/error1.C b/gcc/testsuite/g++.dg/lookup/error1.C new file mode 100644 index 0000000000..3eb4b97213 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/error1.C @@ -0,0 +1,10 @@ +// PR c++/17609 +// Origin: <papadopo@shfj.cea.fr> +// { dg-do compile } + +namespace N { int i; } // { dg-message "N::i" } +void foo() { i; } // { dg-error "not declared" } + // { dg-message "suggested alternative" "suggested alternative" { target *-*-* } 6 } + +using namespace N; +void bar() { i; } diff --git a/gcc/testsuite/g++.dg/lookup/exception1.C b/gcc/testsuite/g++.dg/lookup/exception1.C new file mode 100644 index 0000000000..b5fcd0a6c4 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/exception1.C @@ -0,0 +1,33 @@ +/* PR 2743 */ +/* { dg-do compile } */ + +namespace ns { + class Exception + { + }; +} + +namespace ns +{ + class Test { + public: + inline Test() throw( Exception ); + inline Test(int n ) throw( Exception ); + private: + int i; + }; +} + +// This line used to fail because Exception wasn't looked up in the +// right scope. +ns::Test::Test() throw( Exception ) : i( 1 ) +{ +} + +ns::Test::Test( int n ) throw( Exception ) : i( n ) +{ +} + +int main(int argc, char* argv[]) { + ns::Test test; +} diff --git a/gcc/testsuite/g++.dg/lookup/extern-c-redecl.C b/gcc/testsuite/g++.dg/lookup/extern-c-redecl.C new file mode 100644 index 0000000000..31d100a74f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/extern-c-redecl.C @@ -0,0 +1,11 @@ +// Contributed by Dodji Seketeli <dseketel@redhat.com> +// Origin: PR c++/13699 +// { dg-do compile } + +namespace A { + extern "C" void foo_func () throw(); // { dg-error "conflicts" } +} +// next line should trigger an error because +// it conflicts with previous declaration of foo_func (), due to +// different exception specifications. +extern "C" void foo_func (); // { dg-error "C language|exception specifications" } diff --git a/gcc/testsuite/g++.dg/lookup/extern-c-redecl2.C b/gcc/testsuite/g++.dg/lookup/extern-c-redecl2.C new file mode 100644 index 0000000000..055148f384 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/extern-c-redecl2.C @@ -0,0 +1,21 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/41020 +// { dg-do compile } + +extern "C" +{ + int fork (void); +} + +class frok +{ + int this_errno; + friend int fork (void); +}; + +extern "C" int +fork (void) +{ + frok grouped; + return grouped.this_errno; +} diff --git a/gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C b/gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C new file mode 100644 index 0000000000..56dcefa767 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C @@ -0,0 +1,23 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin: PR c++/41020 +// { dg-options "" } +// { dg-do compile } +// { dg-final { scan-assembler-not "call\[\t \]+\[^\$\]*?_Z4forkv" { target i?86-*-* x86_64-*-* } } } +// { dg-final { scan-assembler "call\[\t \]+_?fork" { target i?86-*-* x86_64-*-* } } } + +extern "C" int fork (void); + +void +foo () +{ + extern int fork (void); + fork (); +} + +extern "C" +int +fork (void) +{ + return 0; +} + diff --git a/gcc/testsuite/g++.dg/lookup/extern-c-redecl4.C b/gcc/testsuite/g++.dg/lookup/extern-c-redecl4.C new file mode 100644 index 0000000000..c385ea701a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/extern-c-redecl4.C @@ -0,0 +1,18 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin: PR c++/41020 + +// { dg-options "" } +// { dg-do compile } +// { dg-final { scan-assembler "call\[\t \]+\[^\$\]*?_Z4forkv" { target i?86-*-* x86_64-*-* } } } + +class frok +{ + int this_errno; + friend int fork (void); +}; + +void +foo () +{ + fork (); +} diff --git a/gcc/testsuite/g++.dg/lookup/extern-c-redecl5.C b/gcc/testsuite/g++.dg/lookup/extern-c-redecl5.C new file mode 100644 index 0000000000..51a342d433 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/extern-c-redecl5.C @@ -0,0 +1,18 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin: PR c++/41020 +// { dg-do compile } + + +class frok +{ + int this_errno; + friend int fork (void); // { dg-error "previous declaration .*?C\\+\\+. linkage" } +}; + +extern "C" int +fork (void) // { dg-error "conflicts with new declaration .*?C. linkage" }} +{ + frok grouped; + return grouped.this_errno; +} + diff --git a/gcc/testsuite/g++.dg/lookup/forscope1.C b/gcc/testsuite/g++.dg/lookup/forscope1.C new file mode 100644 index 0000000000..e694d6f233 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/forscope1.C @@ -0,0 +1,25 @@ +// { dg-do compile } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 4 Sept 2001 <nathan@codesourcery.com> + +// Bug 4206. We were nesting SCOPE_STMTs badly. + +struct A +{ + A (); + ~A (); +}; + + +void Go( ) +{ + while (1) + { + switch (1) { + default: {} + } + A d; + } + +} diff --git a/gcc/testsuite/g++.dg/lookup/forscope2.C b/gcc/testsuite/g++.dg/lookup/forscope2.C new file mode 100644 index 0000000000..1fed957a04 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/forscope2.C @@ -0,0 +1,9 @@ +// { dg-do compile } + +struct S { + void foo() { + for (_ptr; ;) {} // { dg-error "not declared" } + _ptr = 0; + } +}; + diff --git a/gcc/testsuite/g++.dg/lookup/friend1.C b/gcc/testsuite/g++.dg/lookup/friend1.C new file mode 100644 index 0000000000..47fe055651 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend1.C @@ -0,0 +1,15 @@ +// { dg-do compile } + +// Origin: <matz@suse.de> + +// PR c++/9970: In-class friend function definition after +// declaration lexical scope problem. + +void f(); +struct X +{ + enum { k = 1 }; + friend void f() { + char a[k]; + } +}; diff --git a/gcc/testsuite/g++.dg/lookup/friend10.C b/gcc/testsuite/g++.dg/lookup/friend10.C new file mode 100644 index 0000000000..fa2eccbea7 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend10.C @@ -0,0 +1,22 @@ +// PR c++/18681 +// Bug: The friend declaration in A failed to give C::D access to A::B +// as specified in DR 45. + +class A +{ + struct B; + friend class C; +}; + +class C +{ + struct D + { + void f(); + }; +}; + +void C::D::f() +{ + A::B* p; +} diff --git a/gcc/testsuite/g++.dg/lookup/friend11.C b/gcc/testsuite/g++.dg/lookup/friend11.C new file mode 100644 index 0000000000..2b4ffda83c --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend11.C @@ -0,0 +1,23 @@ +/* PR c++/30917 */ +/* This used to ICE */ +/* { dg-do compile } */ + + +class QGList; +unsigned count() { + class QGListIterator { + friend class QGList; + QGListIterator( const QGList & ); // OK, finds ::QGList. + }; + return 0; +} + +// This is valid. +unsigned count2() { + class QGList2; + class QGListIterator2 { + friend class QGList2; + QGListIterator2( const QGList2 & ); + }; + return 0; +} diff --git a/gcc/testsuite/g++.dg/lookup/friend12.C b/gcc/testsuite/g++.dg/lookup/friend12.C new file mode 100644 index 0000000000..95cfd5fb4d --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend12.C @@ -0,0 +1,10 @@ +// PR c++/34912 + +void foo() +{ + struct A + { + friend void bar(); // { dg-error "without prior declaration" } + }; + bar(); // { dg-error "not declared" } +} diff --git a/gcc/testsuite/g++.dg/lookup/friend13.C b/gcc/testsuite/g++.dg/lookup/friend13.C new file mode 100644 index 0000000000..bec71df37b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend13.C @@ -0,0 +1,6 @@ +// PR c++/37558 + +class Foo { + friend class Bar; + friend void func(const class Bar*); +}; diff --git a/gcc/testsuite/g++.dg/lookup/friend14.C b/gcc/testsuite/g++.dg/lookup/friend14.C new file mode 100644 index 0000000000..5c244112a3 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend14.C @@ -0,0 +1,17 @@ +// PR c++/35109 + +struct C; +void f() { + struct A { + friend struct B; + friend struct C; + void g() + { + B *b; // { dg-error "not declared" } + C* c; // OK, finds ::C + } + }; + C *c; // OK, finds ::C + struct B {}; + B *b; // OK, now it isn't hidden +} diff --git a/gcc/testsuite/g++.dg/lookup/friend15.C b/gcc/testsuite/g++.dg/lookup/friend15.C new file mode 100644 index 0000000000..1e271fc3f0 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend15.C @@ -0,0 +1,12 @@ +// Origin: PR c++/35109 +// { dg-do compile } + +void foo() +{ + struct A + { + friend class B; + }; + B::B() {} // { dg-error "has not been declared" } +// { dg-error "expected" "expected" { target *-*-* } 10 } +} diff --git a/gcc/testsuite/g++.dg/lookup/friend2.C b/gcc/testsuite/g++.dg/lookup/friend2.C new file mode 100644 index 0000000000..765c69b67e --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend2.C @@ -0,0 +1,21 @@ +// { dg-do compile } + +// Origin: Albert Chin <bugzilla-gcc@thewrittenword.com> +// Wolfgang Bangerth <bangerth@dealii.org> + +// PR c++/14513, unqualified lookup of friend class. + +struct S { + void test (void); +}; + +namespace NS { + class X { + friend class S; + static int *i; // { dg-error "private" } + }; +} + +void S::test () { + NS::X::i; // { dg-error "this context" } +} diff --git a/gcc/testsuite/g++.dg/lookup/friend3.C b/gcc/testsuite/g++.dg/lookup/friend3.C new file mode 100644 index 0000000000..2a58dd8ca0 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend3.C @@ -0,0 +1,19 @@ +// Copyright (C) 2004 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +// Friend name lookup in class defined outside its namespace + +namespace A { + class B; + class C; +} + +class A::B { + friend class C; + typedef int i; +}; + +class A::C { + A::B::i j; +}; diff --git a/gcc/testsuite/g++.dg/lookup/friend4.C b/gcc/testsuite/g++.dg/lookup/friend4.C new file mode 100644 index 0000000000..86ac915610 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend4.C @@ -0,0 +1,22 @@ +// Copyright (C) 2004 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +// Friend name lookup in class defined outside its namespace +// (Local class case) + +void f() { + class A { + class B; + class C; + }; + + class A::B { + friend class C; + typedef int i; + }; + + class A::C { + A::B::i j; + }; +} diff --git a/gcc/testsuite/g++.dg/lookup/friend5.C b/gcc/testsuite/g++.dg/lookup/friend5.C new file mode 100644 index 0000000000..5be37bbd5a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend5.C @@ -0,0 +1,34 @@ +// { dg-do compile } + +// Origin: aroach@stoic.electriceyeball.com + +// PR c++/3332: Friend function lookup in class defined outside its +// namespace + +namespace N +{ + class A; +} + +class N::A +{ + void x(); + friend void func(void); +}; + +namespace N +{ + void func(void); +} + +void N::func(void) +{ + N::A a; + a.x(); +} + +int main() +{ + return 0; +} + diff --git a/gcc/testsuite/g++.dg/lookup/friend6.C b/gcc/testsuite/g++.dg/lookup/friend6.C new file mode 100644 index 0000000000..e3dafb1d6b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend6.C @@ -0,0 +1,15 @@ +// { dg-do compile } + +// Origin: Matt Austern <austern@apple.com> + +// PR c++/19258: Wrong lookup scope for friend defined in class. + +class X { + template<class T> friend int ff(T*, int y=anX.x) { return y; } + int f() { return ff(&anX); } + + static X anX; + int x; +}; + +X dummy; diff --git a/gcc/testsuite/g++.dg/lookup/friend7.C b/gcc/testsuite/g++.dg/lookup/friend7.C new file mode 100644 index 0000000000..ce9b79f8fe --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend7.C @@ -0,0 +1,19 @@ +// { dg-do compile } +// PR c++/7874: Don't inject friend functions into global name space. + +namespace N { template<typename T> struct A { friend void f(A) { } }; } +int main() +{ + N::A<int> a; + N::f(a); // { dg-error "not a member" } +} + +struct S { friend void g(); friend void h(S); }; +struct T { friend void g(); friend void h(T); }; +void i() { + g(); // { dg-error "not declared" } + S s; + h(s); + T t; + h(t); +} diff --git a/gcc/testsuite/g++.dg/lookup/friend8.C b/gcc/testsuite/g++.dg/lookup/friend8.C new file mode 100644 index 0000000000..e9992cdadf --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend8.C @@ -0,0 +1,12 @@ +// Test that we look up a friend declared at top level ahead of an +// undeclared friend found by argument dependent lookup. + +// { dg-do run } + +int f(int) { return 0; } + +struct S { + friend int f(char) { return 1; } +}; + +int main () { return f('a'); } diff --git a/gcc/testsuite/g++.dg/lookup/friend9.C b/gcc/testsuite/g++.dg/lookup/friend9.C new file mode 100644 index 0000000000..caf685c3ec --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend9.C @@ -0,0 +1,23 @@ +// PR c++/25492 + +class Base { +public: + class Nested {}; +}; + +class Derived:public Base { +public: + class Nested { + public: + void m(); + }; + class AnotherNested { + friend class Nested; + AnotherNested() {} + }; +}; + +void Derived::Nested::m() { + Derived::AnotherNested instance; + +} diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class1.C b/gcc/testsuite/g++.dg/lookup/hidden-class1.C new file mode 100644 index 0000000000..b3be4e8e94 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class1.C @@ -0,0 +1,8 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + friend class B; + B *b; // { dg-error "type|expected" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class10.C b/gcc/testsuite/g++.dg/lookup/hidden-class10.C new file mode 100644 index 0000000000..c9b5ca9f66 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class10.C @@ -0,0 +1,11 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + +// Verify that a friend class is hidden even if it overrides a builtin +// function name. + +class A { + friend class abort; + abort *b; // { dg-error "type|expected" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class11.C b/gcc/testsuite/g++.dg/lookup/hidden-class11.C new file mode 100644 index 0000000000..8432e32d85 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class11.C @@ -0,0 +1,23 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + +// Verify that a friend class is hidden even if it is hidden by a non-builtin +// function name. + +namespace M { + void F (void); + class F; +} + +namespace N { + void F(void); + class A { + friend class F; + }; +} + +using namespace M; +using namespace N; + +class F *b; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class12.C b/gcc/testsuite/g++.dg/lookup/hidden-class12.C new file mode 100644 index 0000000000..4a3f2d7618 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class12.C @@ -0,0 +1,24 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/36019 +// { dg-do compile } + +struct F { + static const int x = 0; +}; + +struct A { + template <typename A> + static int f () + { + return A::x; + } +}; + + +int +main () +{ + int i = A::f<F> (); + return i; +} + diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class13.C b/gcc/testsuite/g++.dg/lookup/hidden-class13.C new file mode 100644 index 0000000000..2f685b2cb3 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class13.C @@ -0,0 +1,25 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/36019 +// { dg-do compile } + +struct F { + static const int x = 0; +}; + +struct B { + template <typename B> + struct C + { + static int f () + { + return B::x; + } + }; +}; + +int +main () +{ + int j = B::C<F>::f (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class14.C b/gcc/testsuite/g++.dg/lookup/hidden-class14.C new file mode 100644 index 0000000000..99bd6731b1 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class14.C @@ -0,0 +1,23 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/36019 +// { dg-do compile } + +struct F { + static const int x = 0; + typedef int A; +}; + +struct A { + template <typename A> + struct G : public F + { + static const A i = 0; + }; +}; + +int +main () +{ + return A::G<F>::i ; +} + diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class15.C b/gcc/testsuite/g++.dg/lookup/hidden-class15.C new file mode 100644 index 0000000000..b0ed660a6a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class15.C @@ -0,0 +1,30 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/36019 +// { dg-do compile } + +struct F { + static const int y = 0; +}; + +struct A { + static const int x = 0; +}; + +struct B : public A { + template <typename A> + struct C + { + static int f () + { + return A::x; // { dg-error "'x' is not a member of 'F'" } + } + }; +}; + +int +main () +{ + int j = B::C<F>::f (); + return 0; +} + diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class16.C b/gcc/testsuite/g++.dg/lookup/hidden-class16.C new file mode 100644 index 0000000000..25cc402940 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class16.C @@ -0,0 +1,27 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/36019 +// { dg-do compile } + +struct F { + static const int y = 0; +}; + +struct A { + static const int x = 0; +}; + +struct B : public A { + template <typename A> + static int f () + { + return A::x; // { dg-error "'x' is not a member of 'F'" } + } +}; + +int +main () +{ + int j = B::f<F> (); + return 0; +} + diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class2.C b/gcc/testsuite/g++.dg/lookup/hidden-class2.C new file mode 100644 index 0000000000..19287a5fb2 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class2.C @@ -0,0 +1,9 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + friend class B; +}; + +class B* b; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class3.C b/gcc/testsuite/g++.dg/lookup/hidden-class3.C new file mode 100644 index 0000000000..50a7e331cb --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class3.C @@ -0,0 +1,10 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + friend class B; + + class B; + B *b; +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class4.C b/gcc/testsuite/g++.dg/lookup/hidden-class4.C new file mode 100644 index 0000000000..c407692caf --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class4.C @@ -0,0 +1,10 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + friend class B; +}; + +class B *b; +B *c; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class5.C b/gcc/testsuite/g++.dg/lookup/hidden-class5.C new file mode 100644 index 0000000000..c2413546bd --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class5.C @@ -0,0 +1,9 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + friend class B; +}; + +B* b; // { dg-error "type|expected" } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class6.C b/gcc/testsuite/g++.dg/lookup/hidden-class6.C new file mode 100644 index 0000000000..9642535391 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class6.C @@ -0,0 +1,14 @@ +// { dg-do compile } + +// Origin: Jay Cox <jaycox@gimp.org> + +// PR c++/1016: Name lookup for injected friend class + +class B; + +namespace N { + class A { + friend class B; + B* b; + }; +} diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class7.C b/gcc/testsuite/g++.dg/lookup/hidden-class7.C new file mode 100644 index 0000000000..a46ae711d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class7.C @@ -0,0 +1,13 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + friend class B; +}; + +class C { + friend class B; +}; + +B *b; // { dg-error "type|expected" } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class8.C b/gcc/testsuite/g++.dg/lookup/hidden-class8.C new file mode 100644 index 0000000000..ea4e2f1bbd --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class8.C @@ -0,0 +1,12 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +namespace N { + class A { + friend class B; + }; +} + +class N::B { // { dg-error "not name a class" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-class9.C b/gcc/testsuite/g++.dg/lookup/hidden-class9.C new file mode 100644 index 0000000000..de86b12694 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-class9.C @@ -0,0 +1,11 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +namespace N { + class A { + friend class B; + }; +} + +using N::B; // { dg-error "declared" } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class1.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class1.C new file mode 100644 index 0000000000..8cdb235e8f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class1.C @@ -0,0 +1,8 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + template <class T> friend class B; + B<int> *b; // { dg-error "type|expected" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class10.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class10.C new file mode 100644 index 0000000000..2134635a26 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class10.C @@ -0,0 +1,12 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +namespace N { + class A { + template <class T> friend class B; + }; +} + +template <class T> class N::B { // { dg-error "not name a class" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class11.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class11.C new file mode 100644 index 0000000000..6e8cbdbb65 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class11.C @@ -0,0 +1,11 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +namespace N { + class A { + template <class T> friend class B; + }; +} + +using N::B; // { dg-error "declared" } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class2.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class2.C new file mode 100644 index 0000000000..56ba76b3ae --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class2.C @@ -0,0 +1,9 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + template <class T> friend class B; +}; + +class B* b; // { dg-error "argument required|invalid" } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class3.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class3.C new file mode 100644 index 0000000000..3f96622ea4 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class3.C @@ -0,0 +1,9 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + template <class T> friend class B; + template <class T> class B; + B<int> *b; +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class4.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class4.C new file mode 100644 index 0000000000..3d085e2249 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class4.C @@ -0,0 +1,9 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + template <class T> friend class B; +}; + +B<int> *b; // { dg-error "type|expected" } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class5.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class5.C new file mode 100644 index 0000000000..e6b30b291f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class5.C @@ -0,0 +1,10 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + template <class T> friend class B; +}; + +template <class T> class B; +B<int>* b; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class6.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class6.C new file mode 100644 index 0000000000..2072695ba7 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class6.C @@ -0,0 +1,11 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class B; +namespace N { + class A { + template <class T> friend class B; + B* b; + }; +} diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class7.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class7.C new file mode 100644 index 0000000000..19dd952489 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class7.C @@ -0,0 +1,13 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + template <class T> friend class B; +}; + +class C { + template <class T> friend class B; +}; + +B<int> *b; // { dg-error "type|expected" } diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class8.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class8.C new file mode 100644 index 0000000000..247c78cf37 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class8.C @@ -0,0 +1,11 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + template <class T> friend class B; +}; + +class C { + friend class B; // { dg-error "argument required|friend" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/hidden-temp-class9.C b/gcc/testsuite/g++.dg/lookup/hidden-temp-class9.C new file mode 100644 index 0000000000..783139b66a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/hidden-temp-class9.C @@ -0,0 +1,11 @@ +// Copyright (C) 2005 Free Software Foundation +// Contributed by Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net> +// { dg-do compile } + +class A { + friend class B; +}; + +class C { + template <class T> friend class B; // { dg-error "not a template" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/java1.C b/gcc/testsuite/g++.dg/lookup/java1.C new file mode 100644 index 0000000000..0d9b22ee1d --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/java1.C @@ -0,0 +1,68 @@ +// { dg-do compile } +// { dg-options "-fdollars-in-identifiers" } +// Origin: Giovanni Bajo <giovannibajo at libero dot it> +// Make sure that Java special functions can be called correctly. + +extern "Java" +{ + typedef __java_int jint; + namespace java + { + namespace lang + { + class Class; + class Object; + class Throwable {}; + class Foo; + } + } +} + +typedef struct java::lang::Object* jobject; +typedef struct java::lang::Throwable* jthrowable; +typedef class java::lang::Class* jclass; +using java::lang::Foo; + +class Foo : public java::lang::Throwable +{ +public: + static ::java::lang::Class class$; +}; + + +/* + * Step 1: no declarations. A declaration for _Jv_Throw is created. + */ + +void Bar1(void) +{ + Foo* f = new java::lang::Foo; // { dg-error "call to Java constructor" } + throw (f); +} + + +/* + * Step 2: constructor declaration + */ + +extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__)); + +void Bar2(void) +{ + Foo* f = new java::lang::Foo; + throw (f); +} + + +/* + * Step 3: overloads + */ + +jobject _Jv_AllocObject (jclass, jint, float) __attribute__((__malloc__)); +void _Jv_Throw (int, float) __attribute__ ((__noreturn__)); + +void Bar3(void) +{ + Foo* f = new java::lang::Foo; // { dg-error "should never be overloaded" } + throw (f); // { dg-error "should never be overloaded" } +} diff --git a/gcc/testsuite/g++.dg/lookup/java2.C b/gcc/testsuite/g++.dg/lookup/java2.C new file mode 100644 index 0000000000..26fd36922b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/java2.C @@ -0,0 +1,47 @@ +// { dg-do compile } +// { dg-options "-fdollars-in-identifiers" } +// Origin: Giovanni Bajo <giovannibajo at libero dot it> +// Make sure that Java special functions can be called correctly. +// (continue from java1.C) + +extern "Java" +{ + typedef __java_int jint; + namespace java + { + namespace lang + { + class Class; + class Object; + class Throwable {}; + class Foo; + } + } +} + +typedef struct java::lang::Object* jobject; +typedef struct java::lang::Throwable* jthrowable; +typedef class java::lang::Class* jclass; +using java::lang::Foo; + +class Foo : public java::lang::Throwable +{ +public: + static ::java::lang::Class class$; +}; + +/* + * Step 4: Manual declaration of _Jv_Throw + * This is the last case we need to test. In the other file we're testing + * the compiler is able to generate an artifical declaration for this + * function, so we need to test here if it works with a normal declaration. + */ + +extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__)); +extern "C" void _Jv_Throw (jthrowable) __attribute__ ((__noreturn__)); + +void Bar4(void) +{ + Foo* f = new java::lang::Foo; + throw (f); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig1.C b/gcc/testsuite/g++.dg/lookup/koenig1.C new file mode 100644 index 0000000000..7273727194 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig1.C @@ -0,0 +1,13 @@ +// { dg-do compile } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Mar 2003 <nathan@codesourcery.com> + +// PR 10026. We ICE'd + +class X; + +void foo() { + X x(1); // { dg-error "incomplete type" "" } + bar(x); // { dg-error "not declared" "" } +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig10.C b/gcc/testsuite/g++.dg/lookup/koenig10.C new file mode 100644 index 0000000000..f2fce9cf74 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig10.C @@ -0,0 +1,12 @@ +// Test for proper handling of class-scope enums. + +struct A +{ + enum E { e }; + friend void f (E); +}; + +int main() +{ + f(A::e); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig11.C b/gcc/testsuite/g++.dg/lookup/koenig11.C new file mode 100644 index 0000000000..dab853bf0f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig11.C @@ -0,0 +1,12 @@ +// Test that we treat unions like other classes in arg-dep lookup. + +union U +{ + friend void f (U); +}; + +int main() +{ + U u; + f(u); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig12.C b/gcc/testsuite/g++.dg/lookup/koenig12.C new file mode 100644 index 0000000000..c135899390 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig12.C @@ -0,0 +1,18 @@ +// PR c++/41305 +// We got into infinite recursion instantiating the B<U> series. + +template <class T> struct A { }; +template <class T, class U = A<T> > struct B; +template <class T> struct C { }; + +template <class T, class U> struct B: C<B<U> > +{ + friend void f(B) { } +}; + +B<int> b; + +int main() +{ + f(b); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig13.C b/gcc/testsuite/g++.dg/lookup/koenig13.C new file mode 100644 index 0000000000..625a181f62 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig13.C @@ -0,0 +1,16 @@ +// PR c++/42687 +// DR 705 + +namespace N +{ + struct S { }; + void f(const S &) { } +} + +void f(const N::S &) { } + +int main() +{ + N::S v; + (f)(v); // no ambiguity: ADL is prevented with (), only ::f is considered +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig2.C b/gcc/testsuite/g++.dg/lookup/koenig2.C new file mode 100644 index 0000000000..04f9525899 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig2.C @@ -0,0 +1,15 @@ +struct S +{ + template <typename T> void operator() (T) {} +}; + +namespace N +{ + S s; + struct A {} a; +} + +using N::s; + +void f () { s(N::a); } + diff --git a/gcc/testsuite/g++.dg/lookup/koenig3.C b/gcc/testsuite/g++.dg/lookup/koenig3.C new file mode 100644 index 0000000000..c5dedbe708 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig3.C @@ -0,0 +1,13 @@ +extern "C" void abort (); + +struct S { +}; +void f(S, int) { abort(); } +void f(S, double) {} + +S s; + +int main() { + extern void f(S, int); + f(s, 3.0); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig4.C b/gcc/testsuite/g++.dg/lookup/koenig4.C new file mode 100644 index 0000000000..49fa5eaa65 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig4.C @@ -0,0 +1,21 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 5 Oct 2004 <nathan@codesourcery.com> + +// Origin: Wolfgang Bangerth <bangerth@dealii.org> +// Incorrect koenig lookup + +struct A {}; + +struct B { + static void foo(); + static void bar(const A &); +}; + +void bar(const A &){} + +void B::foo () { + A a; + bar (a); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig5.C b/gcc/testsuite/g++.dg/lookup/koenig5.C new file mode 100644 index 0000000000..c44543bd52 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig5.C @@ -0,0 +1,49 @@ +// Koenig lookup is not defined as intended in the std. DR 218 gives +// an indication of what is meant. This test case encapsulates the +// current conservative behaviour + +// Copyright (C) 2006 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 27 Aug 2006 <nathan@codesourcery.com> + +namespace N +{ + struct A {}; + void One (...); // { dg-message "N::One" } + void (*Two) (...); // { dg-message "N::Two" } + namespace Three {} // { dg-message "N::Three" } +} + +namespace M +{ + struct B {}; + struct One {}; // { dg-message "M::One" } + void (*Two) (...); // { dg-message "M::Two" } + void Three (...); // { dg-message "M::Three" } +} + +namespace O +{ + struct C {}; + void Two (...); // { dg-message "O::Two" } +} + +void g (N::A *a, M::B *b, O::C *c) +{ + One (a); // ok + One (a, b); // ok + One (b); // { dg-error "not declared" } + // { dg-message "suggested alternatives" "suggested alternative for One" { target *-*-* } 34 } + + Two (c); // ok + Two (a, c); // ok + Two (a); // { dg-error "not declared" } + // { dg-message "suggested alternatives" "suggested alternative for Two" { target *-*-* } 39 } + Two (a, a); // error masked by earlier error + Two (b); // error masked by earlier error + Two (a, b); // error masked by earlier error + + Three (b); // ok + Three (a, b); // ok + Three (a); // { dg-error "not declared" } + // { dg-message "suggested alternatives" "suggested alternative for Three" { target *-*-* } 47 } +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig6.C b/gcc/testsuite/g++.dg/lookup/koenig6.C new file mode 100644 index 0000000000..9fdf771e0c --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig6.C @@ -0,0 +1,18 @@ +// PR c++/17365 +// ADL should not find B::N. + +namespace A +{ + namespace B + { + template <typename T> struct N {int n_;}; + } + template <typename T> int N( T p ) { return p->n_; } + template <typename T> void f( T p ) { N(p); } // #1 +} +int main() +{ + A::B::N<int> n; + A::f(&n); + return 0; +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig7.C b/gcc/testsuite/g++.dg/lookup/koenig7.C new file mode 100644 index 0000000000..bc54ba96b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig7.C @@ -0,0 +1,12 @@ +// PR c++/34870 + +template <typename T> +struct Foo +{ + friend void func(const Foo &) {} +}; + +void check(const Foo<int> & x) +{ + func(x); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig8.C b/gcc/testsuite/g++.dg/lookup/koenig8.C new file mode 100644 index 0000000000..b5558552dc --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig8.C @@ -0,0 +1,14 @@ +// PR c++/42026, DR 239 +// The local extern declaration prevents arg-dependent lookup. +// { dg-do link } + +namespace NS { + class T { }; + void g(T, int); +} +NS::T parm; +void g(NS::T, float) { } +int main() { + extern void g(NS::T, float); + g(parm, 1); +} diff --git a/gcc/testsuite/g++.dg/lookup/koenig9.C b/gcc/testsuite/g++.dg/lookup/koenig9.C new file mode 100644 index 0000000000..f867a32ecc --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/koenig9.C @@ -0,0 +1,25 @@ +// Test for sensible handling of template-ids with arg-dep lookup. +// This is still an open issue. + +namespace N +{ + struct A { }; + void f(void (*)(int, N::A)); +} + +namespace M +{ + struct B { }; + void f(void (*)(B, N::A)); +} + +template <class T> +void g(T, N::A); + +void g(); + +int main() +{ + f(g<int>); + f(g<M::B>); +} diff --git a/gcc/testsuite/g++.dg/lookup/linkage1.C b/gcc/testsuite/g++.dg/lookup/linkage1.C new file mode 100644 index 0000000000..6f6bdfdea8 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/linkage1.C @@ -0,0 +1,4 @@ +// DR 563 + +extern int i; // { dg-error "linkage" } +extern "C" int i; // { dg-error "linkage" } diff --git a/gcc/testsuite/g++.dg/lookup/linkage2.C b/gcc/testsuite/g++.dg/lookup/linkage2.C new file mode 100644 index 0000000000..994264d3eb --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/linkage2.C @@ -0,0 +1,7 @@ +// PR c++/27227 + +namespace x { + extern "C" const int y; +} +using x::y; +extern "C" int const y=0; diff --git a/gcc/testsuite/g++.dg/lookup/main1.C b/gcc/testsuite/g++.dg/lookup/main1.C new file mode 100644 index 0000000000..1de834235a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/main1.C @@ -0,0 +1,3 @@ +struct main {}; + +int main () {} diff --git a/gcc/testsuite/g++.dg/lookup/member1.C b/gcc/testsuite/g++.dg/lookup/member1.C new file mode 100644 index 0000000000..82bb657f50 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/member1.C @@ -0,0 +1,11 @@ +// PR c++/14186 + +struct Base +{ + enum { Derived }; +}; + +class Derived : public Base +{ + Derived(); +}; diff --git a/gcc/testsuite/g++.dg/lookup/name-clash1.C b/gcc/testsuite/g++.dg/lookup/name-clash1.C new file mode 100644 index 0000000000..6ee4be350a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash1.C @@ -0,0 +1,20 @@ +// { dg-do compile } + +// Origin: Jakub Jelinek <jakub@redhat.com> +// PR c++/5402 + +struct A +{ + struct B {}; +}; + +struct C +{ + typedef int B; +}; + +struct D : A +{ + struct E : C {}; + struct B {}; +}; diff --git a/gcc/testsuite/g++.dg/lookup/name-clash2.C b/gcc/testsuite/g++.dg/lookup/name-clash2.C new file mode 100644 index 0000000000..c200eeebd3 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash2.C @@ -0,0 +1,16 @@ +// { dg-do compile } + +// Origin: Sven Bilke <bilkes@mail.nih.gov> +// PR c++/9777 + +struct A +{ + struct X {}; + struct Y { void X(); }; +}; + +struct B : A +{ + struct Y : A::Y {}; + struct X : A::X {}; +}; diff --git a/gcc/testsuite/g++.dg/lookup/name-clash3.C b/gcc/testsuite/g++.dg/lookup/name-clash3.C new file mode 100644 index 0000000000..eb52a7c10c --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash3.C @@ -0,0 +1,14 @@ +// { dg-do compile } + +// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de> +// PR c++/12102 + +struct A +{ + struct C {} C; +}; + +struct B : A +{ + struct C {} C; +}; diff --git a/gcc/testsuite/g++.dg/lookup/name-clash4.C b/gcc/testsuite/g++.dg/lookup/name-clash4.C new file mode 100644 index 0000000000..490f7500ec --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash4.C @@ -0,0 +1,12 @@ +// { dg-do compile } + +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> + +// PR c++/18100: Invalid nested type. + +struct A +{ + template<int> struct A {}; // { dg-error "same name" } +}; + +A::A<0> a; // { dg-error "not a template|constructor" } diff --git a/gcc/testsuite/g++.dg/lookup/name-clash5.C b/gcc/testsuite/g++.dg/lookup/name-clash5.C new file mode 100644 index 0000000000..7f220d8877 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash5.C @@ -0,0 +1,13 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + +// C++ Standard, 3.3, clause 4: +// "[Note: a namespace name or a class template name must be unique in its +// declarative region (7.3.2, clause 14). ]" + +namespace N +{ // { dg-error "previous declaration" } +} + +class N; // { dg-error "redeclared" } diff --git a/gcc/testsuite/g++.dg/lookup/name-clash6.C b/gcc/testsuite/g++.dg/lookup/name-clash6.C new file mode 100644 index 0000000000..63a0b15bf5 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash6.C @@ -0,0 +1,13 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + +// C++ Standard, 3.3, clause 4: +// "[Note: a namespace name or a class template name must be unique in its +// declarative region (7.3.2, clause 14). ]" + +class N; // { dg-error "previous declaration" } + +namespace N +{ // { dg-error "redeclared" } +} diff --git a/gcc/testsuite/g++.dg/lookup/name-clash7.C b/gcc/testsuite/g++.dg/lookup/name-clash7.C new file mode 100644 index 0000000000..5c0690aa85 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash7.C @@ -0,0 +1,11 @@ +// PR c++/28513 + +class foo { // { dg-error "changes meaning" } +public: + typedef int bar; +}; + +class baz { +public: + foo::bar foo; // { dg-error "declaration" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/name-clash8.C b/gcc/testsuite/g++.dg/lookup/name-clash8.C new file mode 100644 index 0000000000..40c487d6a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/name-clash8.C @@ -0,0 +1,8 @@ +// PR c++/38278 + +struct foo { }; +void bar(); + +struct baz { + static foo (bar)(); +}; diff --git a/gcc/testsuite/g++.dg/lookup/nested1.C b/gcc/testsuite/g++.dg/lookup/nested1.C new file mode 100644 index 0000000000..c8988e278d --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/nested1.C @@ -0,0 +1,25 @@ +// Build don't link: +// +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Raymond <raymond@magma.magma-da.com>. +// +// PR c++/47 The parser failed to resolve 'B' in the return type of +// A::C::D::foo. + +class A { +public: + class B; + class C; +}; + +class A::B { +}; + +class A::C { + class D; +}; + +class A::C::D { +public: + B* foo(); +}; diff --git a/gcc/testsuite/g++.dg/lookup/new1.C b/gcc/testsuite/g++.dg/lookup/new1.C new file mode 100644 index 0000000000..11a6d97ddf --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/new1.C @@ -0,0 +1,14 @@ +// { dg-do compile } +// Origin: <igodard at rational dot com> +// PR c++/2518: operator new must not be looked up in local scope + +int main() { + int i; + void* operator new(__SIZE_TYPE__ s, int* p); + int* e = new(&i) int; // { dg-error "no matching function" } + // { dg-message "candidate" "candidate note" { target *-*-* } 8 } + int* f = new int; + return 0; +} + +// { dg-message "operator new|candidate expects" "" { target *-*-* } 0 } diff --git a/gcc/testsuite/g++.dg/lookup/new2.C b/gcc/testsuite/g++.dg/lookup/new2.C new file mode 100644 index 0000000000..d468182c18 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/new2.C @@ -0,0 +1,11 @@ +// { dg-do compile } +// Reject [de-]allocation functions declared in a namespace, or +// declared as static. + +namespace A { + void* operator new(__SIZE_TYPE__ s, int* p); // { dg-error "namespace" } + void operator delete(void*); // { dg-error "namespace" } +} + +static void* operator new(__SIZE_TYPE__ s, int* p); // { dg-error "static" } +static void operator delete(void*); // { dg-error "static" } diff --git a/gcc/testsuite/g++.dg/lookup/ns1.C b/gcc/testsuite/g++.dg/lookup/ns1.C new file mode 100644 index 0000000000..feeaf751ca --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ns1.C @@ -0,0 +1,22 @@ +// PR c++/12862 + +typedef int Thingo; + +namespace A +{ + void + Thingo(); +} + +void +A::Thingo() +{ + ; +} + +int +main() +{ + A::Thingo(); + return 0; +} diff --git a/gcc/testsuite/g++.dg/lookup/ns2.C b/gcc/testsuite/g++.dg/lookup/ns2.C new file mode 100644 index 0000000000..2ad2ec0e3a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ns2.C @@ -0,0 +1,17 @@ +// PR c++/18161 + +namespace m +{ + namespace n + { + } +} + +namespace n +{ +} + +namespace o +{ + namespace n = ::m::n; +} diff --git a/gcc/testsuite/g++.dg/lookup/ns3.C b/gcc/testsuite/g++.dg/lookup/ns3.C new file mode 100644 index 0000000000..144cba73da --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ns3.C @@ -0,0 +1,5 @@ +// PR c++/32898 + +namespace N { } + +int N::i; // { dg-error "should have been declared inside" } diff --git a/gcc/testsuite/g++.dg/lookup/ns4.C b/gcc/testsuite/g++.dg/lookup/ns4.C new file mode 100644 index 0000000000..aabfcfcb7c --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ns4.C @@ -0,0 +1,21 @@ +// PR c++/43145 +// { dg-do link } + +namespace N { + void f(); +} + +void N::f() +{ + extern int i; + extern void g(); + i = 1; + g(); +} + +namespace N { + int i; + void g() { } +} + +int main() { } diff --git a/gcc/testsuite/g++.dg/lookup/pretty1.C b/gcc/testsuite/g++.dg/lookup/pretty1.C new file mode 100644 index 0000000000..a03bd3c3e8 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/pretty1.C @@ -0,0 +1 @@ +void foo() { for ( __PRETTY_FUNCTION__ ; ; ) ; } diff --git a/gcc/testsuite/g++.dg/lookup/ptrmem1.C b/gcc/testsuite/g++.dg/lookup/ptrmem1.C new file mode 100644 index 0000000000..5bdef2621f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/ptrmem1.C @@ -0,0 +1,15 @@ +struct A { + virtual void f (); +}; + +struct B : public A { +}; + +struct C : public A { +}; + +struct D : public B, C { + virtual void f (); +}; + +void (D::*p)() = &D::f; diff --git a/gcc/testsuite/g++.dg/lookup/redecl1.C b/gcc/testsuite/g++.dg/lookup/redecl1.C new file mode 100644 index 0000000000..436316ca07 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/redecl1.C @@ -0,0 +1,7 @@ +// PR c++/14668 + +class A {}; // { dg-error "" } +class B { + static A *A; // { dg-error "" } +}; +A *B::A = 0; diff --git a/gcc/testsuite/g++.dg/lookup/scope-operator1.C b/gcc/testsuite/g++.dg/lookup/scope-operator1.C new file mode 100644 index 0000000000..fde36f01ea --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scope-operator1.C @@ -0,0 +1,20 @@ +/* PR c++/250 */ +/* { dg-do compile } */ + +template <class T> void Bar(T *p) +{ +} + +template <class T> class Foo +{ +public: + Foo(T *p) { Bar(p); } + // The global scope operator wasn't respected in this case under gcc 3.0 + void Bar(T *p) { ::Bar<T>(p); } +}; + +int main() +{ + double* d; + Foo<double> f(d); +} diff --git a/gcc/testsuite/g++.dg/lookup/scoped1.C b/gcc/testsuite/g++.dg/lookup/scoped1.C new file mode 100644 index 0000000000..f1d3f403ea --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped1.C @@ -0,0 +1,22 @@ +// Test that explicitly scoped references to static members work even if +// they belong to an inaccessible base. + +struct A +{ + static int i1; + int i2; // { dg-error "inaccessible" "" } + static void f1 (); + void f2 (); +}; + +struct B: private A { }; +struct C: public B +{ + void g () + { + ::A::i1 = 1; + ::A::i2 = 1; // { dg-error "(access)|(context)" "" } + ::A::f1 (); + ::A::f2 (); // { dg-error "" } + } +}; diff --git a/gcc/testsuite/g++.dg/lookup/scoped2.C b/gcc/testsuite/g++.dg/lookup/scoped2.C new file mode 100644 index 0000000000..99cedcec8b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped2.C @@ -0,0 +1,19 @@ +// { dg-do compile } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 16 Sep 2002 <nathan@codesourcery.com> + +// Seg faulted. + +struct Base +{ +}; + +struct Derived : Base +{ + void Foo () + { + Base::Baz (); // { dg-error "is not a member" "" } + + } +}; diff --git a/gcc/testsuite/g++.dg/lookup/scoped3.C b/gcc/testsuite/g++.dg/lookup/scoped3.C new file mode 100644 index 0000000000..12ef8c8a57 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped3.C @@ -0,0 +1,23 @@ + +// { dg-do compile } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com> + +// PR 7964. ICE with scoped method call + +struct A { + virtual void ostr() const; +}; + +class B : public virtual A {}; + +template<typename T> +struct C : public B +{ + void ostr() const + { B::ostr(); } +}; + + +template struct C<int>; diff --git a/gcc/testsuite/g++.dg/lookup/scoped4.C b/gcc/testsuite/g++.dg/lookup/scoped4.C new file mode 100644 index 0000000000..2d9d90a176 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped4.C @@ -0,0 +1,15 @@ +/* PR c++/754 */ +/* { dg-do compile } */ + +namespace foo +{ + namespace bar + { + enum x {foo + }; + enum {ubit0 = 0x0001}; + // Used to get a parse error before "::" token. + int i=foo::bar::ubit0; + } +} + diff --git a/gcc/testsuite/g++.dg/lookup/scoped5.C b/gcc/testsuite/g++.dg/lookup/scoped5.C new file mode 100644 index 0000000000..a4aa7298f2 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped5.C @@ -0,0 +1,19 @@ +// { dg-do compile } + +// Origin: pepeaty@yahoo.com + +// PR c++/10230: ICE while determining if refered non-static member +// is from a base type of the current class. + +class A { +public: + class B { + public: + int a; + }; +}; + +class C { +public: + void f(void) { sizeof(A::B::a); } +}; diff --git a/gcc/testsuite/g++.dg/lookup/scoped6.C b/gcc/testsuite/g++.dg/lookup/scoped6.C new file mode 100644 index 0000000000..b83b08fe94 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped6.C @@ -0,0 +1,17 @@ +template <typename X> +class Foo { + int i; +public: + Foo() { + X::explode(); // { dg-error "" } + } +}; + +class Bar { + Foo<int> foo_; +public: + Bar() {} // { dg-message "instantiated" } +}; + +template class Foo<int>; + diff --git a/gcc/testsuite/g++.dg/lookup/scoped7.C b/gcc/testsuite/g++.dg/lookup/scoped7.C new file mode 100644 index 0000000000..a9d70d06e3 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped7.C @@ -0,0 +1,20 @@ +//PR c++/11507 +// Origin: kai-gcc-bugs@khms.westfalen.de and bangerth@dealii.org +//The new parser used to fail on this. + +// { dg-do compile } + +namespace NS +{ + void foo(bool arg1); +} + +namespace M { + namespace K { + bool Bc(bool x); + } + + void bar() { + NS::foo (K::Bc(true)); // GCC could not find K or Bc. + } +} diff --git a/gcc/testsuite/g++.dg/lookup/scoped8.C b/gcc/testsuite/g++.dg/lookup/scoped8.C new file mode 100644 index 0000000000..2764f75c13 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/scoped8.C @@ -0,0 +1,18 @@ +// { dg-do compile } + +// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de> + +// PR c++/10371: Incorrect tree node built in +// finish_non_static_data_member. + +struct A +{ + int i; // { dg-error "non-static" } +}; + +template <int> struct B +{ + int foo() { return A::i; } // { dg-error "this location" } +}; + +template struct B<0>; diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-1.C b/gcc/testsuite/g++.dg/lookup/strong-using-1.C new file mode 100644 index 0000000000..aa0c5f9be1 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/strong-using-1.C @@ -0,0 +1,16 @@ +// PR c++/13594 (secondary) + +// { dg-options "" } +// { dg-do compile } + +namespace fool { + inline namespace foo { + template <class T> void swap(T, T); + } + template <class T> void swap(T); +} + +int main() { + // we used to fail to look up the associated namespace here + fool::swap(1, 1); +} diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-2.C b/gcc/testsuite/g++.dg/lookup/strong-using-2.C new file mode 100644 index 0000000000..38bb54c2f5 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/strong-using-2.C @@ -0,0 +1,24 @@ +// PR c++/13594 + +// { dg-options "" } +// { dg-do compile } + +namespace foo { + inline namespace foo_impl { + class T; // { dg-error "T" "" } + } +} +namespace bar { + inline namespace bar_impl { + class T; // { dg-error "T" "" } + } + using namespace foo; +} +namespace baz { + using namespace foo; + using namespace bar; +} + +foo::T *t1; +bar::T *t2; +baz::T *t3; // { dg-error "(ambiguous|does not name a type)" "" } diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-3.C b/gcc/testsuite/g++.dg/lookup/strong-using-3.C new file mode 100644 index 0000000000..7679c6f1dc --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/strong-using-3.C @@ -0,0 +1,18 @@ +// PR c++/13659 + +// { dg-options "" } +// { dg-do compile } + +namespace bar { + inline namespace foo { + template <class T> void f(T, T); + } + template <class T> void f(T); +} + +int main() { + // Make sure both declarations are brought in. + using bar::f; + f(1); + f(1, 1); +} diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-4.C b/gcc/testsuite/g++.dg/lookup/strong-using-4.C new file mode 100644 index 0000000000..5ea17844a6 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/strong-using-4.C @@ -0,0 +1,8 @@ +// PR c++/16301 + +// { dg-do compile } + +namespace NS2 +{ + using namespace NS1 __attribute__ ((strong)); // { dg-error "" } +} diff --git a/gcc/testsuite/g++.dg/lookup/strong-using-5.C b/gcc/testsuite/g++.dg/lookup/strong-using-5.C new file mode 100644 index 0000000000..555adb0c9b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/strong-using-5.C @@ -0,0 +1,26 @@ +// PR c++/33486 + +// { dg-options "" } + +namespace A +{ + inline namespace B + { + struct T + { + struct U { }; + U f(); + }; + } + + inline namespace C + { + void g (T::U); + } +} + +int main() +{ + A::T t; + g(t.f()); +} diff --git a/gcc/testsuite/g++.dg/lookup/struct-hack1.C b/gcc/testsuite/g++.dg/lookup/struct-hack1.C new file mode 100644 index 0000000000..e84d65b335 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/struct-hack1.C @@ -0,0 +1,38 @@ +// { dg-do compile } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 19 Apr 2003 <nathan@codesourcery.com> + +// PR 10405. ICE + +#define MEM_ENUM(name) int name; enum name {}; + +struct Base +{ + MEM_ENUM (a) + MEM_ENUM (b) + MEM_ENUM (c) + MEM_ENUM (d) + MEM_ENUM (e) + MEM_ENUM (f) + MEM_ENUM (g) + MEM_ENUM (h) + MEM_ENUM (i) + MEM_ENUM (j) + MEM_ENUM (k) + MEM_ENUM (l) + MEM_ENUM (m) + MEM_ENUM (n) + MEM_ENUM (o) + MEM_ENUM (p) + MEM_ENUM (q) + MEM_ENUM (r) + MEM_ENUM (s) + MEM_ENUM (t) + MEM_ENUM (u) + MEM_ENUM (v) + MEM_ENUM (w) + }; + +struct D : Base {}; + diff --git a/gcc/testsuite/g++.dg/lookup/struct1.C b/gcc/testsuite/g++.dg/lookup/struct1.C new file mode 100644 index 0000000000..f4b83ecf6b --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/struct1.C @@ -0,0 +1,14 @@ +// Various struct lookup tests. We didn't used to complain about +// the definition of C. + +struct A; +typedef struct A B; // { dg-error "previous declaration" } +struct B; // { dg-error "using typedef-name" } + +typedef struct { int i; } C; // { dg-error "previous declaration" } +struct C; // { dg-error "using typedef-name" } + +struct D; +typedef struct D D; +typedef struct D { int i; } D; +typedef struct D D; diff --git a/gcc/testsuite/g++.dg/lookup/struct2.C b/gcc/testsuite/g++.dg/lookup/struct2.C new file mode 100644 index 0000000000..a66f403c29 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/struct2.C @@ -0,0 +1,7 @@ +// PR c++/14510 + +struct c {}; +namespace A { + int c(struct c*req); +} +int A::c(struct c*req) {} diff --git a/gcc/testsuite/g++.dg/lookup/suggestions1.C b/gcc/testsuite/g++.dg/lookup/suggestions1.C new file mode 100644 index 0000000000..1185d58416 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/suggestions1.C @@ -0,0 +1,8 @@ +// { dg-do compile } + +namespace N { namespace M { int foo; } } // { dg-message "N::M::foo" } +int f (void) { return N::foo; } // { dg-error "not a member" } +// { dg-message "suggested alternative" "missing namespace" { target *-*-* } 4 } + +int g (void) { return ::foo; } // { dg-error "not been declared" } +// { dg-message "suggested alternative" "omitted namespace" { target *-*-* } 7 } diff --git a/gcc/testsuite/g++.dg/lookup/template1.C b/gcc/testsuite/g++.dg/lookup/template1.C new file mode 100644 index 0000000000..44b599a6d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/template1.C @@ -0,0 +1,23 @@ +/* PR c++/3009 */ +/* { dg-do run } */ +// According to 14.6.2.4 of C++ Standard: +// "If a base class is a dependent type, a member of that +// class cannot hide a name declared within a template, or a +// name from the template's enclosing scopes." + +class B { +public: + int foo() { return 1; } +}; + +int foo() { return 0; } + +template <class T> class C : public T { +public: + int caller() { return foo(); } // This must be ::foo, not B::foo. +}; + +int main() { + C<B> c; + return c.caller(); // Returns 1 if we got the wrong one. +} diff --git a/gcc/testsuite/g++.dg/lookup/template2.C b/gcc/testsuite/g++.dg/lookup/template2.C new file mode 100644 index 0000000000..0e8921261e --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/template2.C @@ -0,0 +1,31 @@ +// { dg-do compile } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Mar 2003 <nathan@codesourcery.com> + +// PR 10199. Lookup problems + +class X { +public: + template<int d> + int bar (); +}; + +template<int x> +int fooo (); + +template<class T> +void bar (T& g) +{ + int kk = fooo<17>(); // OK + X x; + int k = x.bar<17>(); // Not OK +} + +int main () +{ + X x; + int k=x.bar<17>(); // OK + int n; + bar(n); +} diff --git a/gcc/testsuite/g++.dg/lookup/template3.C b/gcc/testsuite/g++.dg/lookup/template3.C new file mode 100644 index 0000000000..e5f6f18edc --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/template3.C @@ -0,0 +1,35 @@ +// Origin PR c++/47957 +// { dg-do compile } + +struct S +{ + int m; + + S() + : m(0) + { + } +}; + +struct Base +{ + typedef S T; +}; + +template<class T> +struct Derived : public Base +{ + int + foo() + { + T a; // This is Base::T, not the template parameter. + return a.m; + } +}; + +int +main() +{ + Derived<char> d; + return d.foo(); +} diff --git a/gcc/testsuite/g++.dg/lookup/this1.C b/gcc/testsuite/g++.dg/lookup/this1.C new file mode 100644 index 0000000000..20051bf751 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/this1.C @@ -0,0 +1,8 @@ +// PR c++/27581 +// { dg-do compile } + +struct A +{ + template<int> static void foo(); + static void bar() { this->A::foo<0>(); } // { dg-error "unavailable" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/two-stage1.C b/gcc/testsuite/g++.dg/lookup/two-stage1.C new file mode 100644 index 0000000000..db7117656a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/two-stage1.C @@ -0,0 +1,18 @@ +/* PR c++/2437 */ +/* { dg-do run } */ + +// Test of two-stage name lookup. + +int g(double) { return 0; } + +template <class T> struct X +{ + int f() { return g(2); } // should call g(double) +}; + +inline int g(int) { return 1; } + +int main() +{ + return X<int>().f(); // should call g(double), but used to call g(int) +} diff --git a/gcc/testsuite/g++.dg/lookup/two-stage2.C b/gcc/testsuite/g++.dg/lookup/two-stage2.C new file mode 100644 index 0000000000..67d8ab5211 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/two-stage2.C @@ -0,0 +1,19 @@ +// { dg-do compile } +// PR c++/2922 + +char& f(char); + +template<class T> +void g(T t) +{ + char& c1 = f(1); // not dependent + char& c2 = f(t); // dependent +} + +int&f (int); + +int main() +{ + g(2); // two f(char) + g('a'); // two f(char) +} diff --git a/gcc/testsuite/g++.dg/lookup/two-stage3.C b/gcc/testsuite/g++.dg/lookup/two-stage3.C new file mode 100644 index 0000000000..fff853c1ba --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/two-stage3.C @@ -0,0 +1,22 @@ +// { dg-do compile } +// PR c++/2922 + +namespace tpl_ { + +template<class T> +char test(T); + +template<class T> +struct check +{ + static T const t; + enum { value = 1 == sizeof(test(t)) }; +}; + +double test(int); + +} + +bool const two_phase_lookup_supported = tpl_::check<int>::value; + +int compile_time_assert[two_phase_lookup_supported ? 1 : -1]; diff --git a/gcc/testsuite/g++.dg/lookup/two-stage4.C b/gcc/testsuite/g++.dg/lookup/two-stage4.C new file mode 100644 index 0000000000..bbb44afa0d --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/two-stage4.C @@ -0,0 +1,20 @@ + +// Contributed by Douglas Gregor <doug.gregor@gmail.com> + +template<class T> struct wrap {}; + +template<typename T> bool& operator==(wrap<T>, wrap<T>); + +template<typename T> +void g(T, wrap<wrap<int> > x) +{ + bool& b = x == x; // { dg-bogus "invalid initialization of reference" "" { xfail *-*-*} } +} + +template<typename T> int& operator==(wrap<wrap<T> >, wrap<wrap<T> >); + +void h() +{ + wrap<wrap<int> > x; + g(17, x); +} diff --git a/gcc/testsuite/g++.dg/lookup/two-stage5.C b/gcc/testsuite/g++.dg/lookup/two-stage5.C new file mode 100644 index 0000000000..bfc405b998 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/two-stage5.C @@ -0,0 +1,19 @@ +// { dg-do run } +extern "C" void abort (); + +namespace N { +template <class T> T foo (T) { return T (); } +template <class T> T bar (T t) { return foo (t); } +} + +struct S { S (int i = 0): i_ (i) { } int i_; }; + +namespace N { +/* template <> */ S foo (S) { return S (1); } +} + +int main () +{ + if (1 == N::bar (S()).i_) + abort (); +} diff --git a/gcc/testsuite/g++.dg/lookup/typedef1.C b/gcc/testsuite/g++.dg/lookup/typedef1.C new file mode 100644 index 0000000000..f712fc25aa --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/typedef1.C @@ -0,0 +1,32 @@ +// PR c++/33516 +// { dg-do compile } + +struct S1; +typedef S1 T1; +struct S1 { + typedef int U; + T1::U i; +}; +struct S2; +typedef S2 T2; +struct S2 { + typedef int U; +}; +T2::U j; +struct S3; +typedef S3 T3; +struct S3 { + typedef int U; + S3::U i; +}; + +void +foo () +{ + S1 s1; + S2 s2; + S3 s3; + s1.i = 6; + j = 7; + s3.i = 8; +} diff --git a/gcc/testsuite/g++.dg/lookup/used-before-declaration.C b/gcc/testsuite/g++.dg/lookup/used-before-declaration.C new file mode 100644 index 0000000000..b51d270c74 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/used-before-declaration.C @@ -0,0 +1,5 @@ +// Copyroght (C) 2003 Free Software Foundation +// Origin: PR/12832, Jonathan Wakely <redi@gcc.gnu.org> + +void f() { g(); } // { dg-error "not declared" "" } +void g() { } diff --git a/gcc/testsuite/g++.dg/lookup/using-10.C b/gcc/testsuite/g++.dg/lookup/using-10.C new file mode 100644 index 0000000000..1ca8a78320 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using-10.C @@ -0,0 +1,22 @@ +// PR c++/13659 + +// { dg-do compile } + +namespace foo1 { + template <class T> void f(T); +} +namespace foo2 { + template <class T> void f(T, T); +} +namespace foo { + using namespace foo1; + using namespace foo2; +} + +// Make sure we bring in both declarations. +using foo::f; + +int main() { + f(1); + f(1, 1); +} diff --git a/gcc/testsuite/g++.dg/lookup/using.C b/gcc/testsuite/g++.dg/lookup/using.C new file mode 100644 index 0000000000..30e22c067e --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using.C @@ -0,0 +1,23 @@ +// { dg-do compile } + +struct X { }; +struct Y { }; +struct Z { }; + +struct Base { + X f() { return X(); } + Y f() const { return Y(); } +}; + +struct Derived : Base { + using Base::f; + Z f(int) { return Z(); } +}; + +int main() +{ + Derived d; + X x = d.f(); // { dg-bogus "Y" "" } +} + + diff --git a/gcc/testsuite/g++.dg/lookup/using11.C b/gcc/testsuite/g++.dg/lookup/using11.C new file mode 100644 index 0000000000..9eb7e9fe7a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using11.C @@ -0,0 +1,9 @@ +namespace N1 { + enum e { a }; + void e(char); +} + +void f() { + using N1::e; + enum e x; +} diff --git a/gcc/testsuite/g++.dg/lookup/using12.C b/gcc/testsuite/g++.dg/lookup/using12.C new file mode 100644 index 0000000000..4aa5ce6818 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using12.C @@ -0,0 +1,4 @@ +// PR c++/16707 + +int i; +using N::i; // { dg-error "'N' has not been declared" } diff --git a/gcc/testsuite/g++.dg/lookup/using13.C b/gcc/testsuite/g++.dg/lookup/using13.C new file mode 100644 index 0000000000..c102fdcf87 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using13.C @@ -0,0 +1,12 @@ +// { dg-do compile } + +// Origin: Stefan Straßer <sstrasser@systemhaus-gruppe.de> + +// PR c++/20240: + +namespace A { int a; } + +namespace C{ + int a; + using A::a; // { dg-error "already declared" } +} diff --git a/gcc/testsuite/g++.dg/lookup/using14.C b/gcc/testsuite/g++.dg/lookup/using14.C new file mode 100644 index 0000000000..c953bccc21 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using14.C @@ -0,0 +1,9 @@ +// PR c++/21784 +// { dg-options "" } + +namespace mine +{ + int cpow; +} + +using mine::cpow; diff --git a/gcc/testsuite/g++.dg/lookup/using15.C b/gcc/testsuite/g++.dg/lookup/using15.C new file mode 100644 index 0000000000..b5ca3a876f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using15.C @@ -0,0 +1,10 @@ +// PR c++/27933 +// { dg-do compile } + +template<int> struct A +{ + int i; + A() { using i; } // { dg-error "nested-name-specifier|declared" } +}; + +A<0> a; diff --git a/gcc/testsuite/g++.dg/lookup/using16.C b/gcc/testsuite/g++.dg/lookup/using16.C new file mode 100644 index 0000000000..a396afb973 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using16.C @@ -0,0 +1,18 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + +namespace M { + struct S {}; // { dg-error "struct M::S" "candidate 1" } +} + +namespace N { + int S; + struct S {}; // { dg-error "struct N::S" "candidate 2" } +} + +using namespace M; +using namespace N; + +struct ::S s; // { dg-bogus "ambiguous.*ambiguous" "duplicate error" } +// { dg-error "reference to 'S' is ambiguous|invalid type" "" { target *-*-* } 17 }} diff --git a/gcc/testsuite/g++.dg/lookup/using17.C b/gcc/testsuite/g++.dg/lookup/using17.C new file mode 100644 index 0000000000..b98b21a0cd --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using17.C @@ -0,0 +1,14 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + +namespace M { + struct S {}; // { dg-error "struct M::S" "candidate 2" } +} + +int S; +struct S {}; // { dg-error "candidates are: struct S" "candidate 1" } + +using namespace M; + +struct S s; // { dg-error "reference to 'S' is ambiguous|invalid type in declaration" "" } diff --git a/gcc/testsuite/g++.dg/lookup/using18.C b/gcc/testsuite/g++.dg/lookup/using18.C new file mode 100644 index 0000000000..37557148ea --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using18.C @@ -0,0 +1,20 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + +namespace N1 { + void f (); + struct f; // { dg-error "" "candidate" } +} + +namespace N2 { + void f (int); + struct f; // { dg-error "" "candidate" } +} + +namespace M { + using namespace N1; + using namespace N2; +} + +using M::f; // { dg-error "ambiguous" } diff --git a/gcc/testsuite/g++.dg/lookup/using19.C b/gcc/testsuite/g++.dg/lookup/using19.C new file mode 100644 index 0000000000..973998bc02 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using19.C @@ -0,0 +1,21 @@ +// Copyright (C) 2007 Free Software Foundation +// Contributed by Ollie Wild <aaw@google.com> +// { dg-do compile } + + +// C++ Standard, 7.3.3, clause 10: +// "Since a using-declaration is a declaration, the restrictions on +// declarations of the same name in the same declarative region (3.3) also +// apply to using-declarations." + +namespace M +{ + union A; + void B(); +} + +void A(); +union B; + +using M::A; +using M::B; diff --git a/gcc/testsuite/g++.dg/lookup/using2.C b/gcc/testsuite/g++.dg/lookup/using2.C new file mode 100644 index 0000000000..cd878b9fe9 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using2.C @@ -0,0 +1,45 @@ +// Copyright (C) 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Contributed by Gabriel Dos Reis <gdr@codesourcery.com> + +// { dg-do compile } + +namespace N +{ + template<int> void f() {} +} + +using N; // { dg-error "(using-declaration)|(nested-name)" "" } +using ::N; // { dg-error "using-declaration" "" } +using N::f< 0 >; // { dg-error "using-declaration" "" } + +struct A { + template <class T> void f(T); + template <class T> struct X { }; +}; + +struct B : A { + using A::X; // OK + using A::f; // OK +}; + +struct C : A { + using A::f<double>; // { dg-error "using-declaration" "" } + using A::X<int>; // { dg-error "using-declaration" "" } +}; + diff --git a/gcc/testsuite/g++.dg/lookup/using20.C b/gcc/testsuite/g++.dg/lookup/using20.C new file mode 100644 index 0000000000..dc1d293a2e --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using20.C @@ -0,0 +1,18 @@ +// PR c++/40476 + +namespace A +{ + int i; // { dg-error "i" } +} +using namespace A; +namespace B +{ + namespace B2 + { + int i; // { dg-error "i" } + } + using namespace B2; +} +using namespace B; + +int j = ::i; // { dg-error "ambiguous" } diff --git a/gcc/testsuite/g++.dg/lookup/using21.C b/gcc/testsuite/g++.dg/lookup/using21.C new file mode 100644 index 0000000000..3db97b4b4a --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using21.C @@ -0,0 +1,13 @@ +// PR c++/40799 + +namespace Bar { + typedef int A; +} +class CollectionDeleteGuard { +public: + CollectionDeleteGuard(int); +}; +CollectionDeleteGuard::CollectionDeleteGuard(int) +{ + using Bar::A; +} diff --git a/gcc/testsuite/g++.dg/lookup/using22.C b/gcc/testsuite/g++.dg/lookup/using22.C new file mode 100644 index 0000000000..2396f9ab18 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using22.C @@ -0,0 +1,17 @@ +// PR c++/39786 + +namespace A { + char (*f(char *p))[13] { return 0; } +} + +namespace B { + namespace C { + char (*f(int p))[42] { return 0; } + } + using namespace C; +} + +using namespace B; +using namespace A; + +char x[sizeof *::f(0) == 42 ? 1 : -1]; diff --git a/gcc/testsuite/g++.dg/lookup/using3.C b/gcc/testsuite/g++.dg/lookup/using3.C new file mode 100644 index 0000000000..f364275971 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using3.C @@ -0,0 +1,12 @@ +// PR c++/9798 + +namespace std { } +namespace STL { using namespace std; } +namespace std { + using namespace STL; +} +namespace STL { + struct A { + void B() { using namespace std; } + }; +} diff --git a/gcc/testsuite/g++.dg/lookup/using4.C b/gcc/testsuite/g++.dg/lookup/using4.C new file mode 100644 index 0000000000..a6421c8759 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using4.C @@ -0,0 +1,15 @@ +// { dg-do compile } + +// Origin: Richard Guenther <rguenth@tat.physik.uni-tuebingen.de> + +// PR c++/9432: ICE in validate_nonmember_using_decl when decl is a +// SCOPE_REF. + +template <class T> struct Foo; +template <class T> +struct Bar : public Foo<T> { + void foo() + { + using Foo<T>::i; // { dg-error "not a namespace" } + } +}; diff --git a/gcc/testsuite/g++.dg/lookup/using5.C b/gcc/testsuite/g++.dg/lookup/using5.C new file mode 100644 index 0000000000..b443b97742 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using5.C @@ -0,0 +1,17 @@ +// { dg-do compile } + +// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de> + +// PR c++/10554: ICE for member using declaration with failed +// scope name lookup. + +template <typename> struct A +{ + typedef A X; + void foo(); +}; + +template <typename T> struct B : A<T> +{ + using X::foo; // { dg-error "declared|nested-name-specifier|non-member" } +}; diff --git a/gcc/testsuite/g++.dg/lookup/using6.C b/gcc/testsuite/g++.dg/lookup/using6.C new file mode 100644 index 0000000000..416f0b5256 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using6.C @@ -0,0 +1,11 @@ +// { dg-do compile } + +// Origin: Wolfgang Bangerth <bangerth@ticam.utexas.edu> + +// PR c++/9022, nested namespace in using declaration + +namespace gnu { + namespace gcc { + } +} +using gnu::gcc; // { dg-error "namespace" } diff --git a/gcc/testsuite/g++.dg/lookup/using7.C b/gcc/testsuite/g++.dg/lookup/using7.C new file mode 100644 index 0000000000..69e27da470 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using7.C @@ -0,0 +1,12 @@ +template <typename T, bool=T::X> struct A +{ + int i; +}; + +template <typename T> struct B : A<T> // { dg-error "incomplete" } +{ + using A<T>::i; // { dg-error "incomplete" "incomplete" } + // { dg-error "using" "using" { target *-*-* } 8 } +}; + +B<void> b; // { dg-message "instantiated" } diff --git a/gcc/testsuite/g++.dg/lookup/using8.C b/gcc/testsuite/g++.dg/lookup/using8.C new file mode 100644 index 0000000000..26eb4d3252 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using8.C @@ -0,0 +1,19 @@ +// { dg-do compile } +// Origin: Bill Clarke <llib at computer dot org> +// PR c++/11097: using declartion for a converter operator to a nested class +// in a base type + +template <typename T> +struct A +{ + struct Nested {}; + operator Nested*(); +}; + +template <typename T> +struct B : A<T> +{ + using A<T>::operator typename A<T>::Nested*; +}; + +template struct B<int>; diff --git a/gcc/testsuite/g++.dg/lookup/using9.C b/gcc/testsuite/g++.dg/lookup/using9.C new file mode 100644 index 0000000000..32abb5371f --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using9.C @@ -0,0 +1,31 @@ +// { dg-do compile } +// Origin: C++ Standard Draft (7.3.3/12) +// PR c++/2294: using declarations should not conflict, but only cause +// an ambiguous overload set to be created. + +namespace B { + void f(int); // { dg-message "note" } + void f(double); // { dg-message "note" } +} + +namespace C { + void f(int); // { dg-message "note" } + void f(double); // { dg-message "note" } + void f(char); // { dg-message "note" } +} + +void h() +{ + using B::f; + using C::f; + f('h'); + f(1); // { dg-error "ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 22 } + void f(int); // { dg-error "previous using declaration" } +} + +void m() +{ + void f(int); + using B::f; // { dg-error "already declared" } +} |