From e42c407c8ad2b2bf30fdfab1f7cb6948f1949f38 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Mon, 1 Dec 2014 15:26:10 +0000 Subject: [PATCH] constexpr.c (literal_type_p): Return true for void type in C++14. * constexpr.c (literal_type_p): Return true for void type in C++14. * g++.dg/cpp0x/constexpr-function2.C: Limit dg-error to C++11. * g++.dg/cpp0x/constexpr-neg1.C: Likewise. * g++.dg/cpp1y/constexpr-void1.C: New test. From-SVN: r218220 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/constexpr.c | 3 ++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C | 2 +- gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C | 2 +- gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C | 13 +++++++++++++ 6 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c8047612f57..77b2b1e771e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,7 @@ +2014-12-01 Marek Polacek + + * constexpr.c (literal_type_p): Return true for void type in C++14. + 2014-12-01 Paolo Carlini PR c++/60845 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index f4aca4b9408..6fdb9f3657c 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -59,7 +59,8 @@ literal_type_p (tree t) { if (SCALAR_TYPE_P (t) || TREE_CODE (t) == VECTOR_TYPE - || TREE_CODE (t) == REFERENCE_TYPE) + || TREE_CODE (t) == REFERENCE_TYPE + || (VOID_TYPE_P (t) && cxx_dialect >= cxx14)) return true; if (CLASS_TYPE_P (t)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0655cdf0238..715ea975b9b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-12-01 Marek Polacek + + * g++.dg/cpp0x/constexpr-function2.C: Limit dg-error to C++11. + * g++.dg/cpp0x/constexpr-neg1.C: Likewise. + * g++.dg/cpp1y/constexpr-void1.C: New test. + 2014-12-01 Paolo Carlini PR c++/60845 diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C index 8c51c9ddd25..95ee244e56b 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-function2.C @@ -23,7 +23,7 @@ constexpr int area = squarei(side); // { dg-error "side|argument" } int next(constexpr int x) // { dg-error "parameter" } { return x + 1; } -constexpr void f(int x) // { dg-error "return type .void" } +constexpr void f(int x) // { dg-error "return type .void" "" { target c++11_only } } { /* ... */ } constexpr int prev(int x) diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C index 35f5e8e94f4..dfa1d6bf128 100644 --- a/gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-neg1.C @@ -29,7 +29,7 @@ int next(constexpr int x) { // { dg-error "parameter" } extern constexpr int memsz; // { dg-error "definition" } // error: return type is void -constexpr void f(int x) // { dg-error "void" } +constexpr void f(int x) // { dg-error "void" "" { target c++11_only } } { /* ... */ } // error: use of decrement constexpr int prev(int x) diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C new file mode 100644 index 00000000000..10ef5bc8a6e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-void1.C @@ -0,0 +1,13 @@ +// { dg-do compile { target c++14 } } + +struct S +{ + int i = 20; + + constexpr void + foo (void) + { + if (i > 20) + __builtin_abort (); + } +}; -- 2.30.2