My patch to change check_default_argument to call
perform_implicit_conversion_flags in order to get the diagnostics we
want there had the undesired side-effect of causing the instantiation of
templates that would be used by that conversion, even though the
conversion isn't really used. So this patch avoids that by setting
cp_unevaluated_context.
Tested x86_64-pc-linux-gnu, applying to trunk.
commit ce91c2a524880f727a114cc40e0ad94ac6755631
Author: Jason Merrill <ja...@redhat.com>
Date: Tue Sep 4 15:20:32 2012 -0400
PR c++/54198
* decl.c (check_default_argument): Set cp_unevaluated_operand
around call to perform_implicit_conversion_flags.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 8b94e26..8024373 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -10575,8 +10575,10 @@ check_default_argument (tree decl, tree arg)
A default argument expression is implicitly converted to the
parameter type. */
+ ++cp_unevaluated_operand;
perform_implicit_conversion_flags (decl_type, arg, tf_warning_or_error,
LOOKUP_NORMAL);
+ --cp_unevaluated_operand;
if (warn_zero_as_null_pointer_constant
&& c_inhibit_evaluation_warnings == 0
diff --git a/gcc/testsuite/g++.dg/template/defarg15.C b/gcc/testsuite/g++.dg/template/defarg15.C
new file mode 100644
index 0000000..fea3dee
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/defarg15.C
@@ -0,0 +1,19 @@
+// PR c++/54198
+
+template <typename T> void
+refIfNotNull (T* p1)
+{
+ p1->ref;
+}
+template <typename T> struct A
+{
+ A (T* p1)
+ {
+ refIfNotNull (p1);
+ }
+};
+class B;
+class C
+{
+ void getParent (A <B> = 0);
+};