From: Marc Glisse Date: Thu, 9 Oct 2014 13:53:54 +0000 (+0200) Subject: decl.c (grokdeclarator): constexpr only implies const in C++11. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d0ff1cb4d9b1972e0aa9535d77413e12c4e84fa2;p=gcc.git decl.c (grokdeclarator): constexpr only implies const in C++11. 2014-10-09 Marc Glisse gcc/cp/ * decl.c (grokdeclarator): constexpr only implies const in C++11. gcc/testsuite/ * g++.dg/cpp0x/constexpr-52892-1.C: Error on missing const in C++14. * g++.dg/cpp0x/constexpr-array-ptr7.C: Likewise. * g++.dg/cpp0x/constexpr-diag1.C: Add const. * g++.dg/cpp0x/constexpr-diag3.C: Likewise. * g++.dg/cpp0x/constexpr-ex1.C: Likewise. * g++.dg/cpp0x/constexpr-ex2.C: Likewise. * g++.dg/cpp0x/constexpr-ex4.C: Likewise. * g++.dg/cpp0x/constexpr-initlist.C: Likewise. * g++.dg/cpp0x/constexpr-ptrmem.C: Likewise. * g++.dg/cpp0x/constexpr-ptrsub.C: Likewise. * g++.dg/cpp0x/constexpr-ref4.C: Likewise. * g++.dg/cpp0x/constexpr-static6.C: Likewise. From-SVN: r216039 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1f9f4121cd1..ed71ec27ff2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2014-10-09 Marc Glisse + + * decl.c (grokdeclarator): constexpr only implies const in C++11. + 2014-10-08 Jason Merrill PR c++/63405 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 9c8ecc0c4d0..d4adbeb96ba 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -10539,7 +10539,8 @@ grokdeclarator (const cp_declarator *declarator, && !NEW_DELETE_OPNAME_P (unqualified_id)) { cp_cv_quals real_quals = memfn_quals; - if (constexpr_p && sfk != sfk_constructor && sfk != sfk_destructor) + if (cxx_dialect < cxx14 && constexpr_p + && sfk != sfk_constructor && sfk != sfk_destructor) real_quals |= TYPE_QUAL_CONST; type = build_memfn_type (type, ctype, real_quals, rqual); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0cee7d6cf62..ceaf2b35d81 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,18 @@ +2014-10-09 Marc Glisse + + * g++.dg/cpp0x/constexpr-52892-1.C: Error on missing const in C++14. + * g++.dg/cpp0x/constexpr-array-ptr7.C: Likewise. + * g++.dg/cpp0x/constexpr-diag1.C: Add const. + * g++.dg/cpp0x/constexpr-diag3.C: Likewise. + * g++.dg/cpp0x/constexpr-ex1.C: Likewise. + * g++.dg/cpp0x/constexpr-ex2.C: Likewise. + * g++.dg/cpp0x/constexpr-ex4.C: Likewise. + * g++.dg/cpp0x/constexpr-initlist.C: Likewise. + * g++.dg/cpp0x/constexpr-ptrmem.C: Likewise. + * g++.dg/cpp0x/constexpr-ptrsub.C: Likewise. + * g++.dg/cpp0x/constexpr-ref4.C: Likewise. + * g++.dg/cpp0x/constexpr-static6.C: Likewise. + 2014-10-09 Richard Biener PR tree-optimization/63380 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-52892-1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-52892-1.C index 8e6bc49b632..91e1ea72c2d 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-52892-1.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-52892-1.C @@ -24,5 +24,5 @@ constexpr Defer make_deferred(const Function f) { int main() { constexpr auto deferred = make_deferred(&fibonacci); - static_assert(deferred(25) == 75025, "Static fibonacci call failed"); + static_assert(deferred(25) == 75025, "Static fibonacci call failed"); // { dg-error "no match for call" "" { target c++14 } } } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr7.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr7.C index 93f91411447..005f5300d6f 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr7.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array-ptr7.C @@ -17,4 +17,4 @@ S::foo () constexpr S s = { 0,1,2,3,4,5,6,7,8,9,10 }; #define SA(X) static_assert ((X), #X) -SA(s.foo() == 10); +SA(s.foo() == 10); // { dg-error "discards qualifiers" "" { target c++14 } } diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag1.C index 34cdb733e52..6b908b6dff8 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag1.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag1.C @@ -5,7 +5,7 @@ template struct A { T t; - constexpr int f() { return 42; } // { dg-error "enclosing class" } + constexpr int f() const { return 42; } // { dg-error "enclosing class" } }; struct B { B(); operator int(); }; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C index 2a1897b6bfb..580fceb7282 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-diag3.C @@ -16,7 +16,7 @@ int main() struct complex // { dg-message "no constexpr constructor" } { complex(double r, double i) : re(r), im(i) { } - constexpr double real() { return re; } // { dg-error "not a literal type" } + constexpr double real() const { return re; } // { dg-error "not a literal type" } double imag() const { return im; } private: diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C index e541bf9fbdb..c4c052a607a 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex1.C @@ -12,13 +12,13 @@ // 2 defined before first use // NOTE: this is only needed in contexts that require a constant-expression struct S { - constexpr int twice(); - constexpr int t(); // { dg-message "used but never defined" } + constexpr int twice() const; + constexpr int t() const; // { dg-message "used but never defined" } private: static constexpr int val = 7; // constexpr variable }; -constexpr int S::twice() { return val + val; } +constexpr int S::twice() const { return val + val; } constexpr S s = { }; int x1 = s.twice(); // ok int x2 = s.t(); // error: S::t() not defined @@ -44,8 +44,8 @@ const double* p = &x; // the &x forces x into memory // 1 struct complex { constexpr complex(double r, double i) : re(r), im(i) { } - constexpr double real() { return re; } - constexpr double imag() { return im; } + constexpr double real() const { return re; } + constexpr double imag() const { return im; } private: double re; double im; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C index 9e99d6da467..34b557ce76e 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex2.C @@ -7,8 +7,8 @@ // p 4 struct A { constexpr A(int i) : val(i) { } - constexpr operator int() { return val; } - constexpr operator long() { return -1; } + constexpr operator int() const { return val; } + constexpr operator long() const { return -1; } private: int val; }; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex4.C index 7a9086cb7c1..43e738842f4 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ex4.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ex4.C @@ -3,7 +3,7 @@ struct A { constexpr A(int) { } - constexpr operator int() { return 1; }; + constexpr operator int() const { return 1; }; }; template diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist.C index 52fc9ea8caa..6b6cf3dacaa 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist.C @@ -23,11 +23,11 @@ public: template constexpr initializer_list(const E(&array)[N]) : sz(N), start(array) {} - constexpr size_t size() { return sz; } + constexpr size_t size() const { return sz; } - constexpr const E* begin() { return start; } + constexpr const E* begin() const { return start; } - constexpr const E* end() { return start + sz; } + constexpr const E* end() const { return start + sz; } }; template diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem.C index c16fb15e7b8..a16e5c45916 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrmem.C @@ -4,7 +4,7 @@ struct C { // literal type int m; int n; constexpr C(int m) : m(m), n(-m) {} - constexpr bool is_neg() { return m < 0; } + constexpr bool is_neg() const { return m < 0; } }; constexpr bool check1(const C& c, int C:: *pm) { return c.*pm < 0; } // #1 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub.C index 18648d92d2e..6c7dc302e31 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrsub.C @@ -5,7 +5,7 @@ struct array { constexpr array() :x(0) {} - constexpr int const* begin() { return &x; } + constexpr int const* begin() const { return &x; } int x; }; constexpr array aa; diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C index ce1ce5235c0..be3d48ca6f0 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-ref4.C @@ -4,8 +4,8 @@ struct S { int s[1]; - constexpr const int &foo (unsigned i) { return (i < 1 ? 0 : throw 1), s[i]; } - constexpr const int &bar (unsigned i) { return i < 1 ? s[i] : (throw 0, s[i]); } + constexpr const int &foo (unsigned i) const { return (i < 1 ? 0 : throw 1), s[i]; } + constexpr const int &bar (unsigned i) const { return i < 1 ? s[i] : (throw 0, s[i]); } }; int diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-static6.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-static6.C index 78065c3068b..99e456985b6 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-static6.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-static6.C @@ -2,7 +2,7 @@ struct B { - constexpr operator int() { return 4; } + constexpr operator int() const { return 4; } }; template