[lto] Add several C++ testcases.
Kazu Hirata
kazu@codesourcery.com
Mon Jun 12 14:19:00 GMT 2006
Hi,
Attached is a patch to add several C++ testcases.
While working on a patch to kick a default argument out of
TREE_PURPOSE of a type and store it in DECL_INITIAL of a PARM_DECL
instead, I found several things that are not tested in the current C++
testsuite.
This patch makes sure that those things are tested to help avoid
regressions from the aforementioned patch. All of the errors
mentioned in these testcases are issued from places that have
something to do with default arguments.
Here is a description for each testcase:
g++.dg/parse/ctor6.C
--------------------
At one point in developing my DECL_INITIAL patch, g++ complained about
a constructor call being ambiguous in this testcase. This testcase
was reduced from the libstdc++ testsuite. (At that point, I was
observing no new regression in the C++ testsuite.)
g++.dg/parse/defarg11.C
-----------------------
No existing testcase tests the errors in this testcase. To be
precise, g++.old-deja/g++.jason/operator.C comes very close as it
contains:
struct A {
int operator+(int a, int b = 1); // { dg-error "" } two errors on this line
}
However, the line with "operator+" in it triggers two errors, one of
which is
operator.C:11: error: âint A::operator+(int, int)â must take either zero or one argument
which is enough to make dejagnu happy. That is, even if the other
error goes away, dejagnu won't complain here. The same error is
issued with -pedantic for the last two overloaded operators in my
testcase, but they are not tested anywhere else, which I checked by
placing gcc_unrechable at the place issuing the error.
g++.dg/template/friend42.C
--------------------------
Simply, no existing testcase checks for the error message. I again
used the gcc_unreachable trick mentioned above.
g++.dg/template/spec30.C
------------------------
Simply, no existing testcase checks for the error message. I again
used the gcc_unreachable trick mentioned above.
Tested on x86_64-pc-linux-gnu. OK to apply to the LTO branch? What
about mainline (since these are just testcases)?
Kazu Hirata
2006-06-12 Mark Mitchell <mark@codesourcery.com>
Kazu Hirata <kazu@codesourcery.com>
* g++.dg/parse/ctor6.C, g++.dg/parse/defarg11.C,
g++.dg/template/friend42.C, g++.dg/template/spec30.C: New.
Index: testsuite/g++.dg/parse/ctor6.C
===================================================================
--- testsuite/g++.dg/parse/ctor6.C (revision 0)
+++ testsuite/g++.dg/parse/ctor6.C (revision 0)
@@ -0,0 +1,11 @@
+// { dg-do compile }
+
+// There is no ambiguity in finding a right constructor for X b(a).
+
+class X {
+public:
+ X(const X&, int = 3);
+};
+
+extern X a;
+X b(a);
Index: testsuite/g++.dg/parse/defarg11.C
===================================================================
--- testsuite/g++.dg/parse/defarg11.C (revision 0)
+++ testsuite/g++.dg/parse/defarg11.C (revision 0)
@@ -0,0 +1,9 @@
+// { dg-do compile }
+// { dg-options "-pedantic" }
+
+class foo {
+public:
+ void operator& (int = 1); // { dg-error "error: 'void foo::operator&\\(int\\)' cannot have default arguments" }
+ void operator++ (int = 2); // { dg-error "error: 'void foo::operator\\+\\+\\(int\\)' cannot have default arguments" }
+ void operator-- (int = 3); // { dg-error "error: 'void foo::operator--\\(int\\)' cannot have default arguments" }
+};
Index: testsuite/g++.dg/template/friend42.C
===================================================================
--- testsuite/g++.dg/template/friend42.C (revision 0)
+++ testsuite/g++.dg/template/friend42.C (revision 0)
@@ -0,0 +1,8 @@
+// { dg-do compile }
+
+template <class T> void foo (int);
+
+template <class T>
+class Q {
+ friend void foo<T> (int = 3); // { dg-error "error: default arguments are not allowed in declaration of friend template specialization 'void foo<T>\\(int\\)'" }
+};
Index: testsuite/g++.dg/template/spec30.C
===================================================================
--- testsuite/g++.dg/template/spec30.C (revision 0)
+++ testsuite/g++.dg/template/spec30.C (revision 0)
@@ -0,0 +1,15 @@
+// { dg-do compile }
+
+template<int N>
+inline int
+foo (int a)
+{
+ return a;
+}
+
+template<>
+inline int
+foo<0> (int a = 123) // { dg-error "error: default argument specified in explicit specialization" }
+{
+ return a + 1;
+}
More information about the Gcc-patches
mailing list