diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/g++.dg/overload | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/g++.dg/overload')
52 files changed, 1103 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/overload/VLA.C b/gcc/testsuite/g++.dg/overload/VLA.C new file mode 100644 index 000000000..0c748f50c --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/VLA.C @@ -0,0 +1,16 @@ +//Origin: kengole@us.ibm.com + +//PR c++/2478 +// G++ was rejecting this as it could not convert `int (*)[]' to `int (*)[0]'. +// Using the C99 VLA style arrays in a struct. + +// { dg-do compile } + +struct S { + int (*p)[]; +} B; + +void foo() { + int (*p)[]; + B.p=p; // { dg-bogus "cannot convert" } +} diff --git a/gcc/testsuite/g++.dg/overload/addr1.C b/gcc/testsuite/g++.dg/overload/addr1.C new file mode 100644 index 000000000..25856a20f --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/addr1.C @@ -0,0 +1,50 @@ +// { dg-do run } + +// Copyright (C) 2003 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 6 Sep 2003 <nathan@codesourcery.com> +// Origin: Volker Reichelt <reichelt@igpm.rwth-aachen.de> + +// PR c++/11788 we failed to instantiate a decl, and we lost some side +// effects + +static int flag = 0; + +template <typename> struct A +{ + A &active () { flag++;} + + static void foo() {} + + static void bar () {} + static void bar (int) {} + + int m; +}; + +void (*baz ()) () +{ + A<int> a; + return &a.active ().foo; +} + +void (*boz ()) () +{ + A<int> a; + return &a.active ().bar; +} + +int *buz () +{ + A<int> a; + + return &a.active ().m; +} + +int main () +{ + baz (); + boz (); + buz (); + + return flag != 3; +} diff --git a/gcc/testsuite/g++.dg/overload/ambig1.C b/gcc/testsuite/g++.dg/overload/ambig1.C new file mode 100644 index 000000000..d11e00a18 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/ambig1.C @@ -0,0 +1,24 @@ +// [over.best.ics]: For the purpose of ranking implicit conversion +// sequences as described in _over.ics.rank_, the ambiguous conversion +// sequence is treated as a user-defined sequence that is indistinguishable +// from any other user- defined conversion sequence. + +struct A +{ + A(long); + A(char); +}; + +struct B +{ + B(int); +}; + +void f(A); // { dg-message "note" "candidate" } +void f(B); // { dg-message "note" "candidate" } + +int main() +{ + f (42); // { dg-error "ambiguous" "ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 22 } +} diff --git a/gcc/testsuite/g++.dg/overload/ambig2.C b/gcc/testsuite/g++.dg/overload/ambig2.C new file mode 100644 index 000000000..614166f9f --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/ambig2.C @@ -0,0 +1,22 @@ +// Bug: g++ thought that the QChar overload was a viable but ambiguous +// candidate. It isn't viable, because there's no conversion from const +// char * to QChar. + +class QChar { +public: + QChar( char c ); + QChar( unsigned char c ); +}; + +class QString +{ +public: + QString( const char *str ); // deep copy + + QString &insert( unsigned int index, const QString & ); + QString &insert( unsigned int index, QChar ); + QString &prepend( const char* ); +}; + +inline QString &QString::prepend( const char* s ) +{ return insert(0,s); } diff --git a/gcc/testsuite/g++.dg/overload/arg1.C b/gcc/testsuite/g++.dg/overload/arg1.C new file mode 100644 index 000000000..c765a9902 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/arg1.C @@ -0,0 +1,23 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 30 Nov 2004 <nathan@codesourcery.com> + +// PR 17431. copy ctor from user conv +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> + +struct A {}; + +struct B : A +{ + B(int); + B(B &); + B(A); +}; + +void foo(B); + +void bar() +{ + foo(0); +} diff --git a/gcc/testsuite/g++.dg/overload/arg2.C b/gcc/testsuite/g++.dg/overload/arg2.C new file mode 100644 index 000000000..1e39186f7 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/arg2.C @@ -0,0 +1,22 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 30 Nov 2004 <nathan@codesourcery.com> + +// PR 17431. copy ctor from user conv +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> + +struct A {}; + +struct B : A +{ + B(int); + B(A); +}; + +void foo(B); + +void bar() +{ + foo(0); +} diff --git a/gcc/testsuite/g++.dg/overload/arg3.C b/gcc/testsuite/g++.dg/overload/arg3.C new file mode 100644 index 000000000..34624cd22 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/arg3.C @@ -0,0 +1,23 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 30 Nov 2004 <nathan@codesourcery.com> + +// PR 17431. copy ctor from user conv +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> + +struct A {}; + +struct B : A +{ + B(int); // { dg-message "B::B|no known conversion" "" } + B(B&); // { dg-message "note" "" } +}; + +void foo(B); // { dg-error "initializing" } + +void bar() +{ + foo(0); // { dg-error "no matching function" "no matching" } + // { dg-message "candidate" "candidate note" { target *-*-* } 21 } +} diff --git a/gcc/testsuite/g++.dg/overload/arg4.C b/gcc/testsuite/g++.dg/overload/arg4.C new file mode 100644 index 000000000..13e4bad63 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/arg4.C @@ -0,0 +1,29 @@ +// { dg-do compile } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 30 Nov 2004 <nathan@codesourcery.com> + +// PR 17431. copy ctor from user conv +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> + +struct A {}; + +struct B : A +{ + B(int); + B(B&); + B(A); +}; + +struct C +{ + operator B () const; +}; + + +void foo(B); + +void bar() +{ + C c; + foo(c);} diff --git a/gcc/testsuite/g++.dg/overload/arg5.C b/gcc/testsuite/g++.dg/overload/arg5.C new file mode 100644 index 000000000..63c66d4a0 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/arg5.C @@ -0,0 +1,24 @@ +// PR c++/34111 + +class QChar +{ +}; +struct QString +{ + QString(QChar); +}; +struct QPainter +{ + void drawText (int x, int y, const QString &); +}; + + class KHEChar:public QChar + { + public:KHEChar (QChar C); + }; + +void +drawByte (QPainter * P, char, KHEChar B) +{ + P->drawText (0, 0, B); +} diff --git a/gcc/testsuite/g++.dg/overload/autoptr1.C b/gcc/testsuite/g++.dg/overload/autoptr1.C new file mode 100644 index 000000000..fc8108350 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/autoptr1.C @@ -0,0 +1,29 @@ +// PR c++/35773 + +template< typename T > +class auto_ptr +{ + struct auto_ptr_ref { }; +public: + auto_ptr(auto_ptr&); + auto_ptr(auto_ptr_ref); + + operator auto_ptr_ref(); +}; + +template< typename T > +class reference_wrapper +{ +public: + reference_wrapper(T& t); + operator T& () const; +}; + +struct X { }; + +void f(auto_ptr< X >); + +void g(reference_wrapper< auto_ptr< X > > r) +{ + f(r); +} diff --git a/gcc/testsuite/g++.dg/overload/builtin1.C b/gcc/testsuite/g++.dg/overload/builtin1.C new file mode 100644 index 000000000..fdd208135 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/builtin1.C @@ -0,0 +1,18 @@ +// Test that we don't discard builtin candidates inappropriately. + +struct B { }; + +struct A { + operator int (); + operator B (); +}; + +void operator+ (B, B); // { dg-message "operator" "operator" } + +int main () +{ + A a; + a + a; // { dg-error "ambiguous" "ambiguous" } + // { dg-message "operator" "match candidate text" { target *-*-* } 15 } + // { dg-message "candidates" "candidates" { target *-*-* } 15 } +} diff --git a/gcc/testsuite/g++.dg/overload/builtin2.C b/gcc/testsuite/g++.dg/overload/builtin2.C new file mode 100644 index 000000000..4f9f52dda --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/builtin2.C @@ -0,0 +1,8 @@ +namespace __gnu_cxx { + void llabs(long long x); +} + +namespace std { + using __gnu_cxx::llabs; + using __gnu_cxx::llabs; +} diff --git a/gcc/testsuite/g++.dg/overload/builtin3.C b/gcc/testsuite/g++.dg/overload/builtin3.C new file mode 100644 index 000000000..dcd9fd02e --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/builtin3.C @@ -0,0 +1,10 @@ +// PR c++/11409 +// { dg-do compile } + +namespace std { + double fabs (double); +} +using std::fabs; + +double (*p) (double) = &fabs; // { dg-bogus "is ambiguous" "" } + diff --git a/gcc/testsuite/g++.dg/overload/cond1.C b/gcc/testsuite/g++.dg/overload/cond1.C new file mode 100644 index 000000000..74f0f3c49 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/cond1.C @@ -0,0 +1,24 @@ +// Test that converting a COND_EXPR to void doesn't result in trying to +// bitwise copy a class with a nontrivial copy constructor (and thus a +// compiler abort). + +// { dg-options "-O" } + +struct A { + virtual ~A() { } +}; + +A a1, a2; +inline A& one () { return a1; } +inline A& two () { return a2; } + +inline void f (int i) +{ + i ? a1 : a2; + i ? one() : two(); +} + +int main () +{ + f (1); +} diff --git a/gcc/testsuite/g++.dg/overload/cond2.C b/gcc/testsuite/g++.dg/overload/cond2.C new file mode 100644 index 000000000..cbcdc6ed0 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/cond2.C @@ -0,0 +1,15 @@ +struct C +{ + operator int(); +}; + +struct D +{ + operator int(); +}; + +int main() +{ + C c; D d; + true ? c : d; +} diff --git a/gcc/testsuite/g++.dg/overload/conv-op1.C b/gcc/testsuite/g++.dg/overload/conv-op1.C new file mode 100644 index 000000000..6a63cbaeb --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/conv-op1.C @@ -0,0 +1,17 @@ +// PR c++/47703 + +typedef void (*pfn)(int &); + +struct A +{ + operator pfn() { return 0; } +}; + +void f() +{ + const int i = 42; + A()(i); // { dg-message "<conversion>" } +} + +// { dg-prune-output "no match" } +// { dg-prune-output "candidate" } diff --git a/gcc/testsuite/g++.dg/overload/copy1.C b/gcc/testsuite/g++.dg/overload/copy1.C new file mode 100644 index 000000000..f0ec385fc --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/copy1.C @@ -0,0 +1,21 @@ +// PR c++/34824 + +struct A; + +struct B +{ + B (A const &); // { dg-message "note" } + B (B &); // { dg-message "note" } +}; + +struct A +{ + A (B); // { dg-error "initializing" } +}; + +B +f (B const& b) +{ + return b; // { dg-error "matching" "matching" } + // { dg-message "candidate" "candidate note" { target *-*-* } 19 } +} diff --git a/gcc/testsuite/g++.dg/overload/defarg1.C b/gcc/testsuite/g++.dg/overload/defarg1.C new file mode 100644 index 000000000..44de73373 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/defarg1.C @@ -0,0 +1,9 @@ +// PR c++/5247 + +template<typename T> +int foo (T t, int = foo(T())); + +int main() +{ + foo(0); // { dg-error "default argument" } +} diff --git a/gcc/testsuite/g++.dg/overload/defarg2.C b/gcc/testsuite/g++.dg/overload/defarg2.C new file mode 100644 index 000000000..d8ecb2fa7 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/defarg2.C @@ -0,0 +1,17 @@ +// PR c++/37971 +// { dg-do compile } + +class C { +private: + static int f(int); + static int f(char); + +public: + static void g(int (*)(int) = f); +}; + +void h() { + /* Although C::f is inaccessible here, it is accessible in the + context of C::g, so there is no error. */ + C::g(); +} diff --git a/gcc/testsuite/g++.dg/overload/defarg3.C b/gcc/testsuite/g++.dg/overload/defarg3.C new file mode 100644 index 000000000..6622e430a --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/defarg3.C @@ -0,0 +1,15 @@ +// PR c++/37971 +// { dg-do compile } + +class C { +private: + static int f(int); // { dg-error "private" } + static int f(char); +}; + +class D { +public: + /* C::f is inaccessible, so this is an error, even if this function + is never called. */ + static void g(int (*)(int) = C::f); // { dg-error "context" } +}; diff --git a/gcc/testsuite/g++.dg/overload/defarg4.C b/gcc/testsuite/g++.dg/overload/defarg4.C new file mode 100644 index 000000000..3fa0751b7 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/defarg4.C @@ -0,0 +1,26 @@ +// Contributed by Dodji Seketeli <dodji@redhat.com> +// Origin PR c++/39987 +// { dg-do compile } + +class foo +{ + template<typename U> + static bool func(const U& x) + {} +public: + template<typename U> + unsigned int Find(const U& x, bool (*pFunc) (const U&) = func) const + {} +}; + +class bar { + bool Initialize(); +protected: + foo b; +}; + +bool bar::Initialize() +{ + b.Find(b); +} + diff --git a/gcc/testsuite/g++.dg/overload/ellipsis1.C b/gcc/testsuite/g++.dg/overload/ellipsis1.C new file mode 100644 index 000000000..3dedaa6be --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/ellipsis1.C @@ -0,0 +1,18 @@ +// PR c++/15142 +// Bug: We were aborting after giving a warning about passing a non-POD. + +struct B { + B() throw() { } + B(const B&) throw() { } +}; + +struct X { + B a; + X& operator=(const X&); +}; + +struct S { S(...); }; + +void SillyFunc() { + throw S(X()); // { dg-error "copy" } +} diff --git a/gcc/testsuite/g++.dg/overload/error1.C b/gcc/testsuite/g++.dg/overload/error1.C new file mode 100644 index 000000000..dd10d9053 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/error1.C @@ -0,0 +1,7 @@ +// { dg-do compile } + +struct S +{ + void f () {} // { dg-error "with" "" } + int f () { return 0; } // { dg-error "overloaded" "" } +}; diff --git a/gcc/testsuite/g++.dg/overload/error2.C b/gcc/testsuite/g++.dg/overload/error2.C new file mode 100644 index 000000000..327062133 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/error2.C @@ -0,0 +1,11 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 18 Oct 2005 <nathan@codesourcery.com> + +// PR 22604 +// Origin: Volker Reichelt <reichelt@gcc.gnu.org> + +struct A +{ + void foo(); // { dg-error "with" "" } + virtual void foo(); // { dg-error "cannot be overloaded" "" } +}; diff --git a/gcc/testsuite/g++.dg/overload/error3.C b/gcc/testsuite/g++.dg/overload/error3.C new file mode 100644 index 000000000..e0003dd88 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/error3.C @@ -0,0 +1,41 @@ +// PR c++/42701 +// Test for error-recovery on code that is ill-formed by DR 147. + +namespace Glib { + class ustring { + public: + typedef unsigned size_type; + ustring(const char* src, size_type n); + ustring(const char* src); + }; +} +namespace Gdk { + class Color { + public: + explicit Color(const Glib::ustring& value); + }; +} +namespace Gtk { + enum StateType { STATE_NORMAL }; + class Widget { + public: + void modify_bg(StateType state, const Gdk::Color& color); + }; + class Label { + public: + void set_text(const Glib::ustring &str); + }; +} +typedef enum Result { eSuccess = 0 } Result; +class MainWindow { + void update_status(Result result); + Gtk::Widget status_frame; + Gtk::Label status_label; +}; +void MainWindow::update_status(Result result) { + switch (result) { + status_frame.modify_bg(Gtk::STATE_NORMAL,Gdk::Color::Color("green")); // { dg-error "" } + status_frame.modify_bg(Gtk::STATE_NORMAL,Gdk::Color::Color("red")); // { dg-error "" } + status_label.set_text("Out of memory"); + } +} diff --git a/gcc/testsuite/g++.dg/overload/extern-C-1.C b/gcc/testsuite/g++.dg/overload/extern-C-1.C new file mode 100644 index 000000000..839a0b49a --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/extern-C-1.C @@ -0,0 +1,17 @@ +// PR c++/34691 + +namespace A { + extern "C" void f(int = 5); // { dg-message "= 5" } +} +namespace B { + extern "C" void f(int = 4); // { dg-message "= 4" } +} + +using A::f; +using B::f; +int main() { + void (*fp)(int) = f; // OK + f(3); // OK + f(); // { dg-error "default argument mismatch" } +} + diff --git a/gcc/testsuite/g++.dg/overload/extern-C-2.C b/gcc/testsuite/g++.dg/overload/extern-C-2.C new file mode 100644 index 000000000..562786c04 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/extern-C-2.C @@ -0,0 +1,22 @@ +// PR c++/39742 + +void f( int, ...); + +struct S +{ +}; + +void +g() +{ + void f( int, ...); + + S t; + + f(1, t); +} + +void +f( int i, ...) +{ +} diff --git a/gcc/testsuite/g++.dg/overload/koenig1.C b/gcc/testsuite/g++.dg/overload/koenig1.C new file mode 100644 index 000000000..a46125919 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/koenig1.C @@ -0,0 +1,19 @@ +// PR c++/9336 +// Bug: The first, invalid call to f caused us to crash on the second, +// valid call. + +namespace N { + template <class T> void f (T); // { dg-message "N::f" } + struct A; +} + +struct B; + +void g () +{ + B *bp; + N::A *ap; + f (bp); // { dg-error "not declared" } + // { dg-message "suggested alternative" "suggested alternative" { target *-*-* } 16 } + f (ap); +} diff --git a/gcc/testsuite/g++.dg/overload/koenig2.C b/gcc/testsuite/g++.dg/overload/koenig2.C new file mode 100644 index 000000000..f35aa1a31 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/koenig2.C @@ -0,0 +1,15 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 18 Oct 2005 <nathan@codesourcery.com> + +// PR 21383 +// Origin: Matthew Hall <mahall@ncsa.uiuc.edu> + +template <class T> +void dummy(T& t); + +void anyfunc(int x); + +void Foo () +{ + anyfunc (&dummy<>); // { dg-error "cannot resolve overload" "" } +} diff --git a/gcc/testsuite/g++.dg/overload/member1.C b/gcc/testsuite/g++.dg/overload/member1.C new file mode 100644 index 000000000..29896a511 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/member1.C @@ -0,0 +1,22 @@ +// { dg-do compile } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 29 Sep 2002 <nathan@codesourcery.com> + +struct X +{ + template<typename T> static void ProcessProxy (); + typedef void (*Callback) (); + void Process (Callback); + + template<typename T> void Process () + { + Process (&ProcessProxy<T>); + } + +}; + +void foo (X *x) +{ + x->Process<int> (); +} diff --git a/gcc/testsuite/g++.dg/overload/member2.C b/gcc/testsuite/g++.dg/overload/member2.C new file mode 100644 index 000000000..b8914146f --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/member2.C @@ -0,0 +1,41 @@ +// { dg-do run } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 17 Oct 2002 <nathan@codesourcery.com> + +// PR 7676. We didn't notice template members were different. + +struct foo +{ + template<class T> + int bar() {return 1;} + + template<int I> + int bar() {return 2;} + +}; + +struct baz : foo +{ + using foo::bar; + template<int I> + int bar () {return 3;} +}; + +int main () +{ + baz b; + foo f; + + if (f.bar<1> () != 2) + return 1; + if (f.bar<int> () != 1) + return 2; + + if (b.bar<1> () != 3) + return 1; + if (b.bar<int> () != 1) + return 2; + + return 0; +} diff --git a/gcc/testsuite/g++.dg/overload/new1.C b/gcc/testsuite/g++.dg/overload/new1.C new file mode 100644 index 000000000..9adb4c072 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/new1.C @@ -0,0 +1,22 @@ +typedef __SIZE_TYPE__ size_t; +void *operator new(size_t, unsigned int); + +struct X{ + X(); + X(int); +}; + + +void f(X *x = new X); // { dg-error "" } + +void f(X *x = new X(4)); // { dg-error "" } + +void f(X *x = new X[4]); // { dg-error "" } + +void f(X *x = new (3) X(6)); // { dg-error "" } + +void f(X *x = new (2) X[10]); // { dg-error "" } +// { dg-message "candidate" "candidate note" { target *-*-* } 18 } +// { dg-message "operator new|candidate expects" "match candidate text" { target *-*-* } 00 } + +void f(X *x = new X[10][5]); // { dg-error "" } diff --git a/gcc/testsuite/g++.dg/overload/operator-star-1.C b/gcc/testsuite/g++.dg/overload/operator-star-1.C new file mode 100644 index 000000000..8780d5f62 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/operator-star-1.C @@ -0,0 +1,27 @@ +// Copyright (C) 2002 Free Software Foundation +// Origin: C++/70 +// Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> +// { dg-do compile } + +template <class T> + struct S; + +template <class T> + void operator* (S<T>, S<T>); + +template <class T> + struct S + { + friend void operator*<> (S, S); // { } // okay + void operator* (T) { } + }; + +template <class T> + void operator* (S<T>, S<T>) { } + +int main() +{ + S<int> s1, s2; + s1 * s2; + s1 * 2; +} diff --git a/gcc/testsuite/g++.dg/overload/operator1.C b/gcc/testsuite/g++.dg/overload/operator1.C new file mode 100644 index 000000000..f4d1f53f1 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/operator1.C @@ -0,0 +1,34 @@ +typedef struct _GdkDrawable GdkDrawable; +typedef struct _GdkDrawable GdkBitmap; +typedef struct _GdkDrawable GdkPixmap; + +class Drawable +{ +public: + operator GdkDrawable* () const; +}; + + +class Pixmap : public Drawable +{ +public: + operator GdkPixmap* () const; + +}; + + +class Bitmap : public Pixmap +{ +public: + operator GdkBitmap* () const; + +}; + +class Event +{ +}; + +Bitmap::operator GdkBitmap* () const +{ + return 0; +} diff --git a/gcc/testsuite/g++.dg/overload/operator2.C b/gcc/testsuite/g++.dg/overload/operator2.C new file mode 100644 index 000000000..aba162244 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/operator2.C @@ -0,0 +1,14 @@ +// PR c++/19966 +// { dg-do compile } + +struct A +{ + static operator int(); // { dg-error "must be a nonstatic" } +}; + +struct B +{ + static int operator*(); // { dg-error "must be either" } +}; + +static operator int(); // { dg-error "must be a nonstatic" } diff --git a/gcc/testsuite/g++.dg/overload/operator3.C b/gcc/testsuite/g++.dg/overload/operator3.C new file mode 100644 index 000000000..ff5696788 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/operator3.C @@ -0,0 +1,31 @@ +// PR c++/32756 +// { dg-do compile } + +// bogus overload warning + +class QString; + +struct QByteArray +{ + QByteArray (); + bool operator!= (const QString & s2) const; +}; + +bool operator!= (const QByteArray & a1, const QByteArray & a2); + +struct QString +{ + QString (); + QString (const QByteArray & a); +}; + +QByteArray abbreviation (); + +void +fromString () +{ + QByteArray zoneAbbrev; + if (abbreviation () != zoneAbbrev) + { + } +} diff --git a/gcc/testsuite/g++.dg/overload/pmf1.C b/gcc/testsuite/g++.dg/overload/pmf1.C new file mode 100644 index 000000000..d20074931 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/pmf1.C @@ -0,0 +1,21 @@ +// { dg-do compile } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 04 Mar 2002 <nathan@codesourcery.com> +// Jason Merrill <jason@redhat.com> + +struct A { int i; }; +struct B: private A {}; +struct C { + C (int A::*); +}; + +int A::*aip = &A::i; + +void f (int B::*) {} // should choose this, even though it's ill-formed +void f (C) {} // even though this would be well-formed + +int main () +{ + f (aip); // { dg-error "'A' is an inaccessible base of 'B'|conversion" "" } +} diff --git a/gcc/testsuite/g++.dg/overload/pmf2.C b/gcc/testsuite/g++.dg/overload/pmf2.C new file mode 100644 index 000000000..e95e1f83a --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/pmf2.C @@ -0,0 +1,20 @@ +// PR c++/561 + +class A { }; + +struct B : public A +{ + void foo (); + void foo (int); + template <class T> + void bar (T); + template <class T> + void bar (T, T); +}; + +int main () +{ + void (A::*f1)() = (void (A::*)()) &B::foo; + void (A::*f2)(int) = (void (A::*)(int)) &B::bar; + void (A::*f3)(int) = (void (A::*)(int)) &B::bar<int>; +} diff --git a/gcc/testsuite/g++.dg/overload/prom1.C b/gcc/testsuite/g++.dg/overload/prom1.C new file mode 100644 index 000000000..9eb387dc4 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/prom1.C @@ -0,0 +1,9 @@ +void foo(signed char) {} +typedef int bar; +void foo(bar) {} + +int main (int, char **) { + char c; + foo(c); + return 0; +} diff --git a/gcc/testsuite/g++.dg/overload/ref1.C b/gcc/testsuite/g++.dg/overload/ref1.C new file mode 100644 index 000000000..e239d88a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/ref1.C @@ -0,0 +1,21 @@ +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 5 Mar 2004 <nathan@codesourcery.com> + +// Origin: schmid@snake.iap.physik.tu-darmstadt.de +// Bug 14397: Bogus access error. + +struct S { + S (int); + S(S const&); + private: + S(S&); +}; + +S foo() +{ + int result = 0; + + S s ((0,S (result))); + + return S (result); +} diff --git a/gcc/testsuite/g++.dg/overload/reftemp1.C b/gcc/testsuite/g++.dg/overload/reftemp1.C new file mode 100644 index 000000000..89f941817 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/reftemp1.C @@ -0,0 +1,13 @@ +// PR c++/25950 + +struct X { + X(); + explicit X(const X&); +}; + +void g(const X&); + +int main() +{ + g(X()); +} diff --git a/gcc/testsuite/g++.dg/overload/reftemp2.C b/gcc/testsuite/g++.dg/overload/reftemp2.C new file mode 100644 index 000000000..365d5b13f --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/reftemp2.C @@ -0,0 +1,23 @@ +// DR 391 says that we always bind a reference to the base subobject; it is +// incorrect to call the A copy constructor to initialize the parameter of +// f. + +int fail; + +struct A { + A() { } + A(const A&) { fail = 1; } +}; +struct B : public A { }; +struct X { + operator B() { return B(); } +}; +X x; + +void f (const A&) { } + +int main() +{ + f(x); + return fail; +} diff --git a/gcc/testsuite/g++.dg/overload/rvalue1.C b/gcc/testsuite/g++.dg/overload/rvalue1.C new file mode 100644 index 000000000..41805949d --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/rvalue1.C @@ -0,0 +1,10 @@ +// PR c++/42655 + +void unused(const bool &) { } + +int main() { + volatile bool x = false; + unused(!!x); // type of "!x" is bool + unused(!x); // type of "!x" is bool +} + diff --git a/gcc/testsuite/g++.dg/overload/scope1.C b/gcc/testsuite/g++.dg/overload/scope1.C new file mode 100644 index 000000000..f783b7613 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/scope1.C @@ -0,0 +1,10 @@ +// PR c++/9868 + +template <typename T> struct D { + void (*p)(); + + void clear() { + D::p(); + } +}; +template class D<bool>; diff --git a/gcc/testsuite/g++.dg/overload/template1.C b/gcc/testsuite/g++.dg/overload/template1.C new file mode 100644 index 000000000..5bfad8464 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/template1.C @@ -0,0 +1,12 @@ +template<typename T> T Foo (int) {T d;} + +void Baz (void (*)(int), int); + +int Foo (); +int Baz (int (*)(), float); + +void Bar () +{ + Baz (Foo, 1.0f); + +} diff --git a/gcc/testsuite/g++.dg/overload/template2.C b/gcc/testsuite/g++.dg/overload/template2.C new file mode 100644 index 000000000..e7bdaa74b --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/template2.C @@ -0,0 +1,8 @@ +typedef int PyObject; +typedef PyObject *(*PyCFunction)(PyObject *, PyObject *); +template<class T> int _clear(PyObject* self); + +void _typeInfo() +{ + reinterpret_cast<PyCFunction>(_clear); // { dg-error "overloaded function" } +} diff --git a/gcc/testsuite/g++.dg/overload/template3.C b/gcc/testsuite/g++.dg/overload/template3.C new file mode 100644 index 000000000..90ccfd8ad --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/template3.C @@ -0,0 +1,15 @@ +// PR c++/33962 +// { dg-do compile } + +template <class T> struct A; + +template <class U> void foo (const U &x, ...); +template <class T> void foo (const A<T> &x, ...); + +void bar (const A<int> &x, const char *y) +{ + foo (x, y); +} + +/* { dg-final { scan-assembler "_Z3fooIiEvRK1AIT_Ez" } } */ +/* { dg-final { scan-assembler-not "_Z3fooI1AIiEEvRKT_z" } } */ diff --git a/gcc/testsuite/g++.dg/overload/template4.C b/gcc/testsuite/g++.dg/overload/template4.C new file mode 100644 index 000000000..8f00d4171 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/template4.C @@ -0,0 +1,24 @@ +// PR c++/35986 +// { dg-do compile } + +namespace +{ + template <int> void foo (...); // { dg-message "foo" } + template <int> void bar (int, ...); // { dg-message "bar" } + void baz (...); // { dg-message "baz" } +} + +template <int> void foo (...); // { dg-message "note" } +template <int> void bar (int, ...); // { dg-message "note" } +void baz (...); // { dg-message "note" } + +void +test () +{ + foo <0> (0); // { dg-error "is ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 18 } + bar <1> (0, 1); // { dg-error "is ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 20 } + baz (0); // { dg-error "is ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 22 } +} diff --git a/gcc/testsuite/g++.dg/overload/unknown1.C b/gcc/testsuite/g++.dg/overload/unknown1.C new file mode 100644 index 000000000..935f8d496 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/unknown1.C @@ -0,0 +1,10 @@ +// { dg-do compile } + +void foo(void); +int foo(int); +template <typename T> void bar(T f); // { dg-message "note" } + +void baz() { + bar(foo); // { dg-error "<unresolved overloaded function type>" } + // { dg-message "candidate" "candidate note" { target *-*-* } 8 } +} diff --git a/gcc/testsuite/g++.dg/overload/using1.C b/gcc/testsuite/g++.dg/overload/using1.C new file mode 100644 index 000000000..bc46c6049 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/using1.C @@ -0,0 +1,11 @@ +void f(); + +namespace N { + using ::f; +} + +bool b; + +void g() { + b = N::f == ::f; +} diff --git a/gcc/testsuite/g++.dg/overload/using2.C b/gcc/testsuite/g++.dg/overload/using2.C new file mode 100644 index 000000000..514d83f34 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/using2.C @@ -0,0 +1,92 @@ +// { dg-do compile } + +// Copyright 2005 Free Software Foundation +// by Alexandre Oliva <aoliva@redhat.com> +// based on https://bugzilla.redhat.com/beta/show_bug.cgi?id=149098 + +// Per the ISO C++ 90 Standard, using declarations before of after a +// declaration of the same function name and prototype should be +// errors (7.3.3/11). However, DR 101's resolution recommends +// accepting such duplicates if they denote the same function, which +// means extern "C" declarations are supposed to match and be +// accepted. + +// This test makes sure we reject or accept regular and using +// declarations regardless of order as appropriate, and that having +// built-in declarations or overloads doesn't affet the outcome. + +namespace std { + extern "C" void exit (int) throw (); // these are built-in (extern "C") + extern "C" void *malloc (__SIZE_TYPE__) throw () __attribute__((malloc)); + + void abort (void) throw (); // these aren't + void _exit (int) throw (); // { dg-message "std::_exit" } + + extern "C" void c1 (void) throw (); + void C1 (void) throw (); // { dg-message "std::C1" } + + extern "C" void c2 (void) throw (); + void C2 (void) throw (); + + extern "C" void c3 (void) throw (); + void C3 (void) throw (); // { dg-message "std::C3" } +} + +namespace other { + extern "C" void c3 (void) throw (); + void C3 (void) throw (); // { dg-message "other::C3" } +} + +using std::exit; +using std::_exit; +using std::c1; +using std::C1; + + extern "C" void exit (int) throw (); + extern "C" void *malloc (__SIZE_TYPE__) throw () __attribute__((malloc)); + + void abort (void) throw (); + void _exit (int) throw (); // { dg-error "conflicts" "conflicts" } + // { dg-message "void _exit" "_exit" { target *-*-* } 49 } + + extern "C" void c1 (void) throw (); + void C1 (void) throw (); // { dg-error "conflicts" "conflicts" } + // { dg-message "void C1" "C1" { target *-*-* } 53 } + + extern "C" void c2 (void) throw (); + void C2 (void) throw (); + + int C3 (int) throw (); + +using std::malloc; +using std::abort; // { dg-error "already declared" } +using std::c2; +using std::C2; // { dg-error "already declared" } + +using std::c3; using other::c3; +using std::C3; using other::C3; + + long C3 (long) throw (); + +int main () { + malloc (0); + exit (0); + + _exit (0); // { dg-error "ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 75 } + abort (); + + c1 (); + C1 (); // { dg-error "ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 80 } + + c2 (); + C2 (); // one might expect an ambiguous call error here as well, but + // we don't add the using decl if we find it to be in error. + + c3 (); + C3 (); // { dg-error "ambiguous" } + // { dg-message "candidate" "candidate note" { target *-*-* } 88 } + C3 (0); + C3 (0l); +} diff --git a/gcc/testsuite/g++.dg/overload/virtual1.C b/gcc/testsuite/g++.dg/overload/virtual1.C new file mode 100644 index 000000000..8940aefd0 --- /dev/null +++ b/gcc/testsuite/g++.dg/overload/virtual1.C @@ -0,0 +1,21 @@ +// Test that explicit scope suprresses virtual lookup even after an +// explicit object. + +extern "C" int printf (const char *, ...); + +struct A +{ + virtual int f () { return 0; } +}; + +struct B: public A +{ + int f () { return 1; } + int g() { return this->A::f(); } +}; + +int main() +{ + B b; + return b.g(); +} |