Patchwork [C++] PR 57419

login
register
mail settings
Submitter Paolo Carlini
Date June 3, 2013, 3:16 p.m.
Message ID <51ACB346.8030405@oracle.com>
Download mbox | patch
Permalink /patch/248312/
State New
Headers show

Comments

Paolo Carlini - June 3, 2013, 3:16 p.m.
Hi,

in this SFINAE issue, finish_qualified_id_expr is called with complain 
== 0 and calls mark_used, which has naked error calls. The 
straightforward fix works well. I'm also taking the occasion to change 
an error to inform (then some testcases must be adjusted).

Tested x86_64-linux.

Thanks,
Paolo.

////////////////////
/gcc/cp
2013-06-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/57419
	* decl2.c (mark_used_sfinae): Add.
	* semantics.c (finish_qualified_id_expr): Use it.
	* cp-tree.h: Update.

/gcc/testsuite
2013-06-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/57419
	* g++.dg/cpp0x/sfinae46.C: New.
	* g++.dg/cpp0x/defaulted13.C: Adjust.
	* g++.dg/cpp0x/defaulted2.C: Likewise.
	* g++.dg/cpp0x/defaulted26.C: Likewise.
	* g++.dg/cpp0x/defaulted3.C: Likewise.
	* g++.dg/cpp0x/error1.C: Likewise.
	* g++.dg/cpp0x/implicit1.C: Likewise.
	* g++.dg/cpp0x/implicit11.C: Likewise.
	* g++.dg/cpp0x/inh-ctor13.C: Likewise.
	* g++.dg/cpp0x/initlist47.C: Likewise.
	* g++.dg/cpp0x/initlist9.C: Likewise.
	* g++.dg/cpp0x/lambda/lambda-errloc.C: Likewise.
	* g++.dg/cpp0x/lambda/lambda-errloc2.C: Likewise.
	* g++.dg/cpp0x/nsdmi-local.C: Likewise.
	* g++.dg/cpp0x/union4.C: Likewise.
	* g++.dg/template/crash108.C: Likewise.
	* g++.dg/template/crash41.C: Likewise.
	* g++.old-deja/g++.jason/local.C: Likewise.
	* g++.old-deja/g++.law/visibility3.C: Likewise.

/libstdc++-v3
2013-06-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/57419
	* testsuite/20_util/default_delete/48631_neg.cc: Adjust.
Jason Merrill - June 3, 2013, 5:55 p.m.
Now that we're using C++, I'm inclined to give the sfinae version the 
same name.

Jason

Patch

Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 199607)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -5278,6 +5278,7 @@  extern bool decl_constant_var_p			(tree);
 extern bool decl_maybe_constant_var_p		(tree);
 extern void check_default_args			(tree);
 extern bool mark_used				(tree);
+extern bool mark_used_sfinae			(tree, tsubst_flags_t);
 extern void finish_static_data_member_decl	(tree, tree, bool, tree, int);
 extern tree cp_build_parm_decl			(tree, tree);
 extern tree get_guard				(tree);
Index: gcc/cp/decl2.c
===================================================================
--- gcc/cp/decl2.c	(revision 199607)
+++ gcc/cp/decl2.c	(working copy)
@@ -4499,7 +4499,7 @@  possibly_inlined_p (tree decl)
    wrong, true otherwise.  */
 
 bool
-mark_used (tree decl)
+mark_used_sfinae (tree decl, tsubst_flags_t complain)
 {
   /* If DECL is a BASELINK for a single function, then treat it just
      like the DECL for the function.  Otherwise, if the BASELINK is
@@ -4537,9 +4537,12 @@  bool
 	      return false;
 	    }
 	}
-      error ("use of deleted function %qD", decl);
-      if (!maybe_explain_implicit_delete (decl))
-	error_at (DECL_SOURCE_LOCATION (decl), "declared here");
+      if (complain & tf_error)
+	{
+	  error ("use of deleted function %qD", decl);
+	  if (!maybe_explain_implicit_delete (decl))
+	    inform (DECL_SOURCE_LOCATION (decl), "declared here");
+	}
       return false;
     }
 
@@ -4552,7 +4555,8 @@  bool
     {
       if (!processing_template_decl && type_uses_auto (TREE_TYPE (decl)))
 	{
-	  error ("use of %qD before deduction of %<auto%>", decl);
+	  if (complain & tf_error)
+	    error ("use of %qD before deduction of %<auto%>", decl);
 	  return false;
 	}
       return true;
@@ -4701,4 +4705,10 @@  bool
   return true;
 }
 
+bool
+mark_used (tree decl)
+{
+  return mark_used_sfinae (decl, tf_warning_or_error);
+}
+
 #include "gt-cp-decl2.h"
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 199607)
+++ gcc/cp/semantics.c	(working copy)
@@ -1778,8 +1778,9 @@  finish_qualified_id_expr (tree qualifying_class,
   if (error_operand_p (expr))
     return error_mark_node;
 
-  if (DECL_P (expr) || BASELINK_P (expr))
-    mark_used (expr);
+  if ((DECL_P (expr) || BASELINK_P (expr))
+      && !mark_used_sfinae (expr, complain))
+    return error_mark_node;
 
   if (template_p)
     check_template_keyword (expr);
Index: gcc/testsuite/g++.dg/cpp0x/defaulted13.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted13.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted13.C	(working copy)
@@ -7,13 +7,13 @@  struct NonCopyable {
 };
 
 template<>
-NonCopyable<int>::NonCopyable(NonCopyable<int> const&) = delete; // { dg-error "declared" }
+NonCopyable<int>::NonCopyable(NonCopyable<int> const&) = delete; // { dg-message "declared" }
 
 template<typename T>
 NonCopyable<T>::NonCopyable(NonCopyable<T> const&) = default;
 
 template<>
-NonCopyable<double>::NonCopyable(NonCopyable<double> const&) = delete; // { dg-error "declared" }
+NonCopyable<double>::NonCopyable(NonCopyable<double> const&) = delete; // { dg-message "declared" }
 
 
 int main()
Index: gcc/testsuite/g++.dg/cpp0x/defaulted2.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted2.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted2.C	(working copy)
@@ -42,7 +42,7 @@  struct E
 struct F
 {
   F() = default;
-  F(const F&) = delete;		// { dg-error "declared" }
+  F(const F&) = delete;		// { dg-message "declared" }
 };
 
 struct G
Index: gcc/testsuite/g++.dg/cpp0x/defaulted26.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted26.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted26.C	(working copy)
@@ -1,7 +1,7 @@ 
 // PR c++/49066
 // { dg-options -std=c++0x }
 
-void foo() = delete;		// { dg-error "declared here" }
+void foo() = delete;		// { dg-message "declared here" }
 void foo();
 
 int main() { foo(); }		// { dg-error "deleted" }
Index: gcc/testsuite/g++.dg/cpp0x/defaulted3.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/defaulted3.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/defaulted3.C	(working copy)
@@ -4,7 +4,7 @@ 
 template<class T>
 struct A {
   template<class U>
-  bool operator==(const A<U>&) = delete; // { dg-error "declared" }
+  bool operator==(const A<U>&) = delete; // { dg-message "declared" }
   operator bool () { return true; }
 };
 
Index: gcc/testsuite/g++.dg/cpp0x/error1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/error1.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/error1.C	(working copy)
@@ -2,7 +2,7 @@ 
 // { dg-do compile }
 // { dg-options "-std=c++0x" }
 
-template<int... N> void foo (int... x[N])	// { dg-error "int \\\[N\\\]\\.\\.\\. x" }
+template<int... N> void foo (int... x[N])	// { dg-message "int \\\[N\\\]\\.\\.\\. x" }
 {
   struct A
   {
Index: gcc/testsuite/g++.dg/cpp0x/implicit1.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/implicit1.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/implicit1.C	(working copy)
@@ -15,7 +15,7 @@  D d;				// { dg-error "deleted" }
 
 struct E
 {
-  ~E() = delete;		// { dg-error "declared here" }
+  ~E() = delete;		// { dg-message "declared here" }
 };
 
 struct F
Index: gcc/testsuite/g++.dg/cpp0x/implicit11.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/implicit11.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/implicit11.C	(working copy)
@@ -4,7 +4,7 @@ 
 
 struct A
 {
-  ~A() = delete;		// { dg-error "declared here" }
+  ~A() = delete;		// { dg-message "declared here" }
 };
 
 struct B: A { };		// { dg-error "deleted" }
Index: gcc/testsuite/g++.dg/cpp0x/inh-ctor13.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/inh-ctor13.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/inh-ctor13.C	(working copy)
@@ -8,7 +8,7 @@  struct A
 
 struct C
 {
-  C() = delete;			// { dg-error "declared here" }
+  C() = delete;			// { dg-message "declared here" }
 };
 
 struct B: A, C
Index: gcc/testsuite/g++.dg/cpp0x/initlist47.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/initlist47.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/initlist47.C	(working copy)
@@ -1,6 +1,6 @@ 
 // { dg-options -std=c++0x }
 
-struct A { ~A() = delete; };	// { dg-error "declared" }
+struct A { ~A() = delete; };	// { dg-message "declared" }
 
 int main()
 {
Index: gcc/testsuite/g++.dg/cpp0x/initlist9.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/initlist9.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/initlist9.C	(working copy)
@@ -8,7 +8,7 @@  struct b
   b() = default;
   ~b() = default;
   b& operator=(const b&) = delete;
-  b(const b&) = delete;		// { dg-error "declared" }
+  b(const b&) = delete;		// { dg-message "declared" }
 
   b(bool _t): t (_t) { }
 };
Index: gcc/testsuite/g++.dg/cpp0x/lambda/lambda-errloc.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-errloc.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-errloc.C	(working copy)
@@ -5,7 +5,7 @@ 
 struct A
 {
   A();
-  A(const A& a) = delete;	// { dg-error "declared" }
+  A(const A& a) = delete;	// { dg-message "declared" }
 };
 
 int main()
Index: gcc/testsuite/g++.dg/cpp0x/lambda/lambda-errloc2.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/lambda/lambda-errloc2.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/lambda/lambda-errloc2.C	(working copy)
@@ -3,7 +3,7 @@ 
 
 struct A {
   A();
-  A(const A&) = delete;		// { dg-error "declared" }
+  A(const A&) = delete;		// { dg-message "declared" }
 };
 
 template <class T>
Index: gcc/testsuite/g++.dg/cpp0x/nsdmi-local.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/nsdmi-local.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/nsdmi-local.C	(working copy)
@@ -3,6 +3,6 @@ 
 
 int main()
 {
-    int q = 1;				 // { dg-error "declared here" }
+    int q = 1;				 // { dg-message "declared here" }
     struct test { int x = q; } instance; // { dg-error "local variable" }
 }
Index: gcc/testsuite/g++.dg/cpp0x/sfinae46.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/sfinae46.C	(revision 0)
+++ gcc/testsuite/g++.dg/cpp0x/sfinae46.C	(working copy)
@@ -0,0 +1,13 @@ 
+// PR c++/57419
+// { dg-do compile { target c++11 } }
+
+template< typename q >
+decltype( &q::f ) t( q ) {}
+
+char t( ... ) { return {}; }
+
+class c { void f() = delete; };
+class d { static void f() = delete; };
+
+static_assert( sizeof( t( c() ) ), "c" );
+static_assert( sizeof( t( d() ) ), "d" );
Index: gcc/testsuite/g++.dg/cpp0x/union4.C
===================================================================
--- gcc/testsuite/g++.dg/cpp0x/union4.C	(revision 199598)
+++ gcc/testsuite/g++.dg/cpp0x/union4.C	(working copy)
@@ -3,7 +3,7 @@ 
 
 struct SFoo
 {
-  SFoo() =delete;		// { dg-error "declared" }
+  SFoo() =delete;		// { dg-message "declared" }
 };
 
 union UFoo			// { dg-error "deleted" }
Index: gcc/testsuite/g++.dg/template/crash108.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash108.C	(revision 199598)
+++ gcc/testsuite/g++.dg/template/crash108.C	(working copy)
@@ -1,5 +1,5 @@ 
 // PR c++/50861
 
 template<class T> struct A {A(int b=k(0));}; // { dg-error "parameter|arguments" }
-void f(int k){A<int> a;} // // { dg-error "declared" }
+void f(int k){A<int> a;} // // { dg-message "declared" }
 // { dg-message "note" "note" { target *-*-* } 3 }
Index: gcc/testsuite/g++.dg/template/crash41.C
===================================================================
--- gcc/testsuite/g++.dg/template/crash41.C	(revision 199598)
+++ gcc/testsuite/g++.dg/template/crash41.C	(working copy)
@@ -1,7 +1,7 @@ 
 // PR c++/22464
 
 template<typename T>
-void do_something(const T* A) // { dg-error "declared" }
+void do_something(const T* A) // { dg-message "declared" }
 { 
   struct helper_t{ 
     helper_t() {  
Index: gcc/testsuite/g++.old-deja/g++.jason/local.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.jason/local.C	(revision 199598)
+++ gcc/testsuite/g++.old-deja/g++.jason/local.C	(working copy)
@@ -5,7 +5,7 @@  int x;
 void f ()
 {
   static int s;
-  int x;			// { dg-error "" } referenced below
+  int x;			// { dg-message "" } referenced below
   extern int q();
 
   struct local {
Index: gcc/testsuite/g++.old-deja/g++.law/visibility3.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.law/visibility3.C	(revision 199598)
+++ gcc/testsuite/g++.old-deja/g++.law/visibility3.C	(working copy)
@@ -11,7 +11,7 @@  int x;
 int main(void)
 {
   static int s;
-  int x; // { dg-error "" } declared
+  int x; // { dg-message "" } declared
   extern int g();
 
   struct local {
Index: libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc
===================================================================
--- libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc	(revision 199598)
+++ libstdc++-v3/testsuite/20_util/default_delete/48631_neg.cc	(working copy)
@@ -27,4 +27,4 @@  struct D : B { };
 D d;
 std::default_delete<B[]> db;
 typedef decltype(db(&d)) type; // { dg-error "use of deleted function" }
-// { dg-error "declared here" "" { target *-*-* } 122 }
+// { dg-prune-output "declared" }