Commit d0ff1cb4 by Marc Glisse Committed by Marc Glisse

decl.c (grokdeclarator): constexpr only implies const in C++11.

2014-10-09  Marc Glisse  <marc.glisse@inria.fr>

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
parent 12d3031b
2014-10-09 Marc Glisse <marc.glisse@inria.fr>
* decl.c (grokdeclarator): constexpr only implies const in C++11.
2014-10-08 Jason Merrill <jason@redhat.com> 2014-10-08 Jason Merrill <jason@redhat.com>
PR c++/63405 PR c++/63405
......
...@@ -10539,7 +10539,8 @@ grokdeclarator (const cp_declarator *declarator, ...@@ -10539,7 +10539,8 @@ grokdeclarator (const cp_declarator *declarator,
&& !NEW_DELETE_OPNAME_P (unqualified_id)) && !NEW_DELETE_OPNAME_P (unqualified_id))
{ {
cp_cv_quals real_quals = memfn_quals; 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; real_quals |= TYPE_QUAL_CONST;
type = build_memfn_type (type, ctype, real_quals, rqual); type = build_memfn_type (type, ctype, real_quals, rqual);
} }
......
2014-10-09 Marc Glisse <marc.glisse@inria.fr>
* 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 <rguenther@suse.de> 2014-10-09 Richard Biener <rguenther@suse.de>
PR tree-optimization/63380 PR tree-optimization/63380
......
...@@ -24,5 +24,5 @@ constexpr Defer<Function> make_deferred(const Function f) { ...@@ -24,5 +24,5 @@ constexpr Defer<Function> make_deferred(const Function f) {
int main() { int main() {
constexpr auto deferred = make_deferred(&fibonacci); 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 } }
} }
...@@ -17,4 +17,4 @@ S::foo () ...@@ -17,4 +17,4 @@ S::foo ()
constexpr S s = { 0,1,2,3,4,5,6,7,8,9,10 }; constexpr S s = { 0,1,2,3,4,5,6,7,8,9,10 };
#define SA(X) static_assert ((X), #X) #define SA(X) static_assert ((X), #X)
SA(s.foo() == 10); SA(s.foo() == 10); // { dg-error "discards qualifiers" "" { target c++14 } }
...@@ -5,7 +5,7 @@ template <class T> ...@@ -5,7 +5,7 @@ template <class T>
struct A struct A
{ {
T t; 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(); }; struct B { B(); operator int(); };
......
...@@ -16,7 +16,7 @@ int main() ...@@ -16,7 +16,7 @@ int main()
struct complex // { dg-message "no constexpr constructor" } struct complex // { dg-message "no constexpr constructor" }
{ {
complex(double r, double i) : re(r), im(i) { } 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; } double imag() const { return im; }
private: private:
......
...@@ -12,13 +12,13 @@ ...@@ -12,13 +12,13 @@
// 2 defined before first use // 2 defined before first use
// NOTE: this is only needed in contexts that require a constant-expression // NOTE: this is only needed in contexts that require a constant-expression
struct S { struct S {
constexpr int twice(); constexpr int twice() const;
constexpr int t(); // { dg-message "used but never defined" } constexpr int t() const; // { dg-message "used but never defined" }
private: private:
static constexpr int val = 7; // constexpr variable 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 = { }; constexpr S s = { };
int x1 = s.twice(); // ok int x1 = s.twice(); // ok
int x2 = s.t(); // error: S::t() not defined int x2 = s.t(); // error: S::t() not defined
...@@ -44,8 +44,8 @@ const double* p = &x; // the &x forces x into memory ...@@ -44,8 +44,8 @@ const double* p = &x; // the &x forces x into memory
// 1 // 1
struct complex { struct complex {
constexpr complex(double r, double i) : re(r), im(i) { } constexpr complex(double r, double i) : re(r), im(i) { }
constexpr double real() { return re; } constexpr double real() const { return re; }
constexpr double imag() { return im; } constexpr double imag() const { return im; }
private: private:
double re; double re;
double im; double im;
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
// p 4 // p 4
struct A { struct A {
constexpr A(int i) : val(i) { } constexpr A(int i) : val(i) { }
constexpr operator int() { return val; } constexpr operator int() const { return val; }
constexpr operator long() { return -1; } constexpr operator long() const { return -1; }
private: private:
int val; int val;
}; };
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
struct A struct A
{ {
constexpr A(int) { } constexpr A(int) { }
constexpr operator int() { return 1; }; constexpr operator int() const { return 1; };
}; };
template <class T> template <class T>
......
...@@ -23,11 +23,11 @@ public: ...@@ -23,11 +23,11 @@ public:
template<size_t N> template<size_t N>
constexpr initializer_list(const E(&array)[N]) : sz(N), start(array) {} 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<class E, size_t N> template<class E, size_t N>
......
...@@ -4,7 +4,7 @@ struct C { // literal type ...@@ -4,7 +4,7 @@ struct C { // literal type
int m; int m;
int n; int n;
constexpr C(int m) : m(m), n(-m) {} 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 constexpr bool check1(const C& c, int C:: *pm) { return c.*pm < 0; } // #1
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
struct array struct array
{ {
constexpr array() :x(0) {} constexpr array() :x(0) {}
constexpr int const* begin() { return &x; } constexpr int const* begin() const { return &x; }
int x; int x;
}; };
constexpr array aa; constexpr array aa;
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
struct S struct S
{ {
int s[1]; int s[1];
constexpr const int &foo (unsigned i) { return (i < 1 ? 0 : throw 1), s[i]; } constexpr const int &foo (unsigned i) const { 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 &bar (unsigned i) const { return i < 1 ? s[i] : (throw 0, s[i]); }
}; };
int int
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
struct B struct B
{ {
constexpr operator int() { return 4; } constexpr operator int() const { return 4; }
}; };
template <int I> template <int I>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment