diff mbox

C++ PATCH for c++/57068 (wrong ref-qualifier error)

Message ID 518B1E25.4090404@redhat.com
State New
Headers show

Commit Message

Jason Merrill May 9, 2013, 3:55 a.m. UTC
A case of giving an error during tentative parsing; we need to wait 
until we know for sure that we're doing something dodgy.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
diff mbox

Patch

commit 4d01649f80e76af9be37b35d166a00990defa978
Author: Jason Merrill <jason@redhat.com>
Date:   Wed May 8 12:33:26 2013 -0400

    	PR c++/57068
    	* decl.c (grokdeclarator): Warn about ref-qualifiers here.
    	* parser.c (cp_parser_ref_qualifier_seq_opt): Not here.
    	* error.c (maybe_warn_cpp0x): s/0x/11/.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a3250a2..bd9afc8 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9577,6 +9577,7 @@  grokdeclarator (const cp_declarator *declarator,
 
 		if (rqual)
 		  {
+		    maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
 		    error ((flags == DTOR_FLAG)
 			   ? "destructors may not be ref-qualified"
 			   : "constructors may not be ref-qualified");
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 48327dd..a75fc4e 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -3404,7 +3404,7 @@  maybe_warn_cpp0x (cpp0x_warn_str str)
 	break;
       case CPP0X_AUTO:
 	pedwarn (input_location, 0,
-		 "C++0x auto only available with -std=c++11 or -std=gnu++11");
+		 "C++11 auto only available with -std=c++11 or -std=gnu++11");
 	break;
       case CPP0X_SCOPED_ENUMS:
 	pedwarn (input_location, 0,
@@ -3453,7 +3453,7 @@  maybe_warn_cpp0x (cpp0x_warn_str str)
       case CPP0X_REF_QUALIFIER:
 	pedwarn (input_location, 0,
 		 "ref-qualifiers "
-		 "only available with -std=c++0x or -std=gnu++0x");
+		 "only available with -std=c++11 or -std=gnu++11");
 	break;
       default:
 	gcc_unreachable ();
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 6de8e1a..8d3f6c7 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -17199,9 +17199,6 @@  cp_parser_ref_qualifier_opt (cp_parser* parser)
 	}
     }
 
-  if (ref_qual)
-    maybe_warn_cpp0x (CPP0X_REF_QUALIFIER);
-
   return ref_qual;
 }
 
diff --git a/gcc/testsuite/g++.dg/parse/ref-qual1.C b/gcc/testsuite/g++.dg/parse/ref-qual1.C
new file mode 100644
index 0000000..e3f60c0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/ref-qual1.C
@@ -0,0 +1,29 @@ 
+// PR c++/57068
+
+enum Enums {
+  Enum1 = 0x00000000,
+  Enum2 = 0x00000001
+};
+
+class Flags {
+public:
+  Flags() : i(0) {}
+  Flags(int i): i(i) {}
+  Flags operator&(Enums f) { return Flags(Enums(i & f)); }
+
+  operator bool() { return i; }
+private:
+  int i;
+};
+
+Flags windowState()
+{
+  return Flags();
+}
+
+int main()
+{
+  if (bool(windowState() & Enum1) == true)
+    return 1;
+  return 0;
+}