Patchwork C++ PATCHes for c++/54020, 54086 (minor constexpr issues)

login
register
mail settings
Submitter Jason Merrill
Date July 25, 2012, 2:55 p.m.
Message ID <501008E6.1050301@redhat.com>
Download mbox | patch
Permalink /patch/173189/
State New
Headers show

Comments

Jason Merrill - July 25, 2012, 2:55 p.m.
54020 notes that we were accepting a constexpr function that is 
ill-formed, no diagnostic required, but it would be easy to give a 
diagnostic for.

54086 suggests that the standard seems to allow constexpr and const 
together.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 2b151043b8e3259d5ec3cb0d6da243317c2a7d68
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jul 25 10:18:34 2012 -0400

    	PR c++/54086
    	* decl.c (grokdeclarator): Allow const and constexpr together.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c37787b..047b2fe 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -9528,8 +9528,6 @@  grokdeclarator (const cp_declarator *declarator,
      the object as `const'.  */
   if (constexpr_p && innermost_code != cdk_function)
     {
-      if (type_quals & TYPE_QUAL_CONST)
-        error ("both %<const%> and %<constexpr%> cannot be used here");
       if (type_quals & TYPE_QUAL_VOLATILE)
         error ("both %<volatile%> and %<constexpr%> cannot be used here");
       if (TREE_CODE (type) != REFERENCE_TYPE)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-const1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-const1.C
new file mode 100644
index 0000000..6ee7225
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-const1.C
@@ -0,0 +1,7 @@ 
+// PR c++/54086
+// { dg-do compile { target c++11 } }
+
+static constexpr const char Data[] = {
+  'D', 'A', 'T', 'A',
+};
+static constexpr const char *data_func() { return Data; }
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-object1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-object1.C
index 4ff398b..6c9d466 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-object1.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-object1.C
@@ -18,8 +18,7 @@  extern constexpr int i2; // { dg-error "definition" }
 // error: missing initializer
 constexpr A1 a2; // { dg-error "uninitialized const" }
 
-// error: duplicate cv
-const constexpr A1 a3 = A1(); // { dg-error "both .const. and .constexpr. cannot" }
+const constexpr A1 a3 = A1();
 
 volatile constexpr A1 a4 = A1(); // { dg-error "both .volatile. and .constexpr. cannot" }