diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2002-12-26 12:23:11 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2002-12-26 12:23:11 +0000 |
commit | aac1406f303436e98da1fc4a7125541502126541 (patch) | |
tree | b5d0e443d07d129ba5e34654dec2cfcdb8cf7dca /gcc | |
parent | 223231230e787e5b7f382d0e5eaa771a00733855 (diff) | |
download | gcc-aac1406f303436e98da1fc4a7125541502126541.zip gcc-aac1406f303436e98da1fc4a7125541502126541.tar.gz gcc-aac1406f303436e98da1fc4a7125541502126541.tar.bz2 |
PR c++/5116, c++/764
cp:
PR c++/5116, c++/764
* call.c (build_new_op): Make sure template class operands are
instantiated.
testsuite:
* g++.dg/template/friend10.C: New test.
* g++.dg/template/conv5.C: New test.
From-SVN: r60514
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/call.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/conv5.C | 22 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/friend10.C | 45 |
5 files changed, 88 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3f4c1d0..2291b73 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2002-12-26 Nathan Sidwell <nathan@codesourcery.com> + + PR c++/5116, c++/764 + * call.c (build_new_op): Make sure template class operands are + instantiated. + 2002-12-24 Nathan Sidwell <nathan@codesourcery.com> PR C++/7964 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 088cc1e..9190870 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3343,6 +3343,10 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3) if (TREE_CODE (arg1) == OFFSET_REF) arg1 = resolve_offset_ref (arg1); arg1 = convert_from_reference (arg1); + if (CLASS_TYPE_P (TREE_TYPE (arg1)) + && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (arg1))) + /* Make sure the template type is instantiated now. */ + instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (arg1))); switch (code) { @@ -3365,12 +3369,18 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3) if (TREE_CODE (arg2) == OFFSET_REF) arg2 = resolve_offset_ref (arg2); arg2 = convert_from_reference (arg2); + if (CLASS_TYPE_P (TREE_TYPE (arg2)) + && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (arg2))) + instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (arg2))); } if (arg3) { if (TREE_CODE (arg3) == OFFSET_REF) arg3 = resolve_offset_ref (arg3); arg3 = convert_from_reference (arg3); + if (CLASS_TYPE_P (TREE_TYPE (arg3)) + && CLASSTYPE_TEMPLATE_INSTANTIATION (TREE_TYPE (arg3))) + instantiate_class_template (TYPE_MAIN_VARIANT (TREE_TYPE (arg3))); } if (code == COND_EXPR) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8196168..a68ab21 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2002-12-26 Nathan Sidwell <nathan@codesourcery.com> + + * g++.dg/template/friend10.C: New test. + * g++.dg/template/conv5.C: New test. + 2002-12-24 Nathan Sidwell <nathan@codesourcery.com> * g++.dg/lookup/scoped3.C: New test. diff --git a/gcc/testsuite/g++.dg/template/conv5.C b/gcc/testsuite/g++.dg/template/conv5.C new file mode 100644 index 0000000..8083543 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/conv5.C @@ -0,0 +1,22 @@ +// { dg-do compile } + +// Copyright (C) 2001 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 26 Dec 2002 <nathan@codesourcery.com> + +// PR 764. Failed to find friend in overload resolution + +template <class T> +struct S +{ + friend bool operator== (const S&, const S&) { + return true; + } +}; + +int main () +{ + // S<int> s; + + const S<int> *p = 0; + *p == *p; // error +} diff --git a/gcc/testsuite/g++.dg/template/friend10.C b/gcc/testsuite/g++.dg/template/friend10.C new file mode 100644 index 0000000..cab5e34 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend10.C @@ -0,0 +1,45 @@ +// { dg-do run } + +// Copyright (C) 2002 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 24 Dec 2002 <nathan@codesourcery.com> + +// PR 5116. template instantiation can add a friend into a namespace, +// and thus change overload resolution. + +#include <iostream> + +static int right; +static int wrong; + +struct Buggy {}; + +template <typename T>struct Handle +{ + Handle(T* p) {} + + operator bool() const { wrong++; return true; } + + friend std::ostream& operator<<(std::ostream& ostr, const Handle& r) + { + right++; + + return ostr << "in operator<<(ostream&, const Handle&)"; + } +}; + +typedef Handle<Buggy> Buggy_h; + +bool cmp (const Buggy_h& b1, const Buggy_h& b2) +{ + std::cout << b1 << " " << b2 << std::endl; + return false; +} + +int main() +{ + Buggy o; + + cmp (&o, &o); + + return !(right == 2 && !wrong); +} |