re PR c++/67592 (A virtual member function declared constexpr fails to trigger a...
authorPaolo Carlini <paolo.carlini@oracle.com>
Fri, 18 Dec 2015 18:18:47 +0000 (18:18 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 18 Dec 2015 18:18:47 +0000 (18:18 +0000)
/cp
2015-12-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/67592
* decl.c (grokdeclarator): Reject constexpr virtual member functions;
in error messages, prefer %<virtual%> and %<constexpr%> to virtual
and constexpr, respectively.

/testsuite
2015-12-18  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/67592
* g++.dg/cpp0x/constexpr-virtual5.C: New.
* g++.dg/cpp0x/pr51463.C: Adjust dg-error string.
* g++.dg/inherit/pure1.C: Likewise.

From-SVN: r231824

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-virtual5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/pr51463.C
gcc/testsuite/g++.dg/inherit/pure1.C

index 89c0a198a8280d2f1fdbeafb74d5265460e3ca1e..d471721f21c3cdf7a8eab370de0e221ea838eef6 100644 (file)
@@ -1,3 +1,10 @@
+2015-12-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/67592
+       * decl.c (grokdeclarator): Reject constexpr virtual member functions;
+       in error messages, prefer %<virtual%> and %<constexpr%> to virtual
+       and constexpr, respectively.
+
 2015-12-18  Patrick Palka  <ppalka@gcc.gnu.org>
 
        PR c++/68831
index 7d45d4dc1f518fd3642cbf7a8a739fd07600464d..a14062bca0d2987ef8d9511d4a53c8114072929e 100644 (file)
@@ -9769,11 +9769,18 @@ grokdeclarator (const cp_declarator *declarator,
   if (storage_class == sc_static)
     staticp = 1 + (decl_context == FIELD);
 
-  if (virtualp && staticp == 2)
+  if (virtualp)
     {
-      error ("member %qD cannot be declared both virtual and static", dname);
-      storage_class = sc_none;
-      staticp = 0;
+      if (staticp == 2)
+       {
+         error ("member %qD cannot be declared both %<virtual%> "
+                "and %<static%>", dname);
+         storage_class = sc_none;
+         staticp = 0;
+       }
+      if (constexpr_p)
+       error ("member %qD cannot be declared both %<virtual%> "
+              "and %<constexpr%>", dname);
     }
   friendp = decl_spec_seq_has_spec_p (declspecs, ds_friend);
 
@@ -10153,7 +10160,8 @@ grokdeclarator (const cp_declarator *declarator,
                      explicitp = 2;
                    if (virtualp)
                      {
-                       permerror (input_location, "constructors cannot be declared virtual");
+                       permerror (input_location,
+                                  "constructors cannot be declared %<virtual%>");
                        virtualp = 0;
                      }
                    if (decl_context == FIELD
@@ -10988,7 +10996,7 @@ grokdeclarator (const cp_declarator *declarator,
                   ARM 9.5 */
                if (virtualp && TREE_CODE (ctype) == UNION_TYPE)
                  {
-                   error ("function %qD declared virtual inside a union",
+                   error ("function %qD declared %<virtual%> inside a union",
                           unqualified_id);
                    return error_mark_node;
                  }
@@ -10997,7 +11005,7 @@ grokdeclarator (const cp_declarator *declarator,
                  {
                    if (virtualp)
                      {
-                       error ("%qD cannot be declared virtual, since it "
+                       error ("%qD cannot be declared %<virtual%>, since it "
                               "is always static",
                               unqualified_id);
                        virtualp = 0;
index 57326d19ee9c385c88ee3e1d71a7d704c1a593aa..dabdceaff4873255f337d5acbf8fd575350870ab 100644 (file)
@@ -1,3 +1,10 @@
+2015-12-18  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/67592
+       * g++.dg/cpp0x/constexpr-virtual5.C: New.
+       * g++.dg/cpp0x/pr51463.C: Adjust dg-error string.
+       * g++.dg/inherit/pure1.C: Likewise.
+
 2015-12-18  Jeff Law  <law@redhat.com>
 
        PR rtl-optimization/49847
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-virtual5.C
new file mode 100644 (file)
index 0000000..895de50
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c+++/67592
+// { dg-do compile { target c++11 } }
+
+struct S {
+  constexpr virtual int f() { return 1; }  // { dg-error "both 'virtual' and 'constexpr'" }
+};
index 6a57e47825cf150e7d2e68490d6bb73e5aa9e3f0..75de47d60e469b490148e64b6c889b757dc1c076 100644 (file)
@@ -3,5 +3,5 @@
 
 struct A
 {
-  static virtual int i = 0;    // { dg-error "both virtual and static|declared as" }
+  static virtual int i = 0;    // { dg-error "both 'virtual' and 'static'|declared as" }
 };
index e825f0098433d339e7433c259b0114375cfba6df..99a5767c787f33970d71df80f6e1eaaa9d43a306 100644 (file)
@@ -9,7 +9,7 @@ struct A
 {
   void foo2() = 0;                 // { dg-error "non-virtual" }
   static void foo3() = 0;          // { dg-error "static member" }
-  virtual static void foo4() = 0;  // { dg-error "both virtual and static" }
+  virtual static void foo4() = 0;  // { dg-error "both 'virtual' and 'static'" }
   virtual void foo5() = 0;         // { dg-error "base class" }
 };