* C++ PATCH for c++/65985 (wrong error with constexpr ctor)
@ 2016-02-18 4:57 Jason Merrill
0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2016-02-18 4:57 UTC (permalink / raw)
To: gcc-patches List
[-- Attachment #1: Type: text/plain, Size: 151 bytes --]
The declaration of __PRETTY_FUNCTION__ was confusing
build_constexpr_constructor_member_initializers.
Tested x86_64-pc-linux-gnu, applying to trunk.
[-- Attachment #2: 65985.patch --]
[-- Type: text/x-patch, Size: 2297 bytes --]
commit aef1a26de333aab5f602f6eb02cfd1ae751bb84f
Author: Jason Merrill <jason@redhat.com>
Date: Wed Feb 17 16:33:50 2016 -0500
PR c++/65985
* constexpr.c (build_constexpr_constructor_member_initializers):
Handle an additional STATEMENT_LIST.
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 0eedfca..d3b04b1 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -528,21 +528,32 @@ build_constexpr_constructor_member_initializers (tree type, tree body)
{
vec<constructor_elt, va_gc> *vec = NULL;
bool ok = true;
- if (TREE_CODE (body) == MUST_NOT_THROW_EXPR
- || TREE_CODE (body) == EH_SPEC_BLOCK)
- body = TREE_OPERAND (body, 0);
- if (TREE_CODE (body) == STATEMENT_LIST)
- {
- for (tree_stmt_iterator i = tsi_start (body);
- !tsi_end_p (i); tsi_next (&i))
- {
- body = tsi_stmt (i);
- if (TREE_CODE (body) == BIND_EXPR)
- break;
- }
+ while (true)
+ switch (TREE_CODE (body))
+ {
+ case MUST_NOT_THROW_EXPR:
+ case EH_SPEC_BLOCK:
+ body = TREE_OPERAND (body, 0);
+ break;
+
+ case STATEMENT_LIST:
+ for (tree_stmt_iterator i = tsi_start (body);
+ !tsi_end_p (i); tsi_next (&i))
+ {
+ body = tsi_stmt (i);
+ if (TREE_CODE (body) == BIND_EXPR)
+ break;
+ }
+ break;
+
+ case BIND_EXPR:
+ body = BIND_EXPR_BODY (body);
+ goto found;
+
+ default:
+ gcc_unreachable ();
}
- if (TREE_CODE (body) == BIND_EXPR)
- body = BIND_EXPR_BODY (body);
+ found:
if (TREE_CODE (body) == CLEANUP_POINT_EXPR)
{
body = TREE_OPERAND (body, 0);
diff --git a/gcc/testsuite/g++.dg/cpp1y/constexpr-assert2.C b/gcc/testsuite/g++.dg/cpp1y/constexpr-assert2.C
new file mode 100644
index 0000000..a329101
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/constexpr-assert2.C
@@ -0,0 +1,31 @@
+// PR c++/65985
+// { dg-do compile { target c++14 } }
+
+#include <cassert>
+
+class Angle
+{
+ int degrees = 0;
+
+ constexpr auto invariant() const noexcept
+ {
+ return 0 <= degrees && degrees < 360;
+ }
+
+public:
+ explicit constexpr Angle(int n) noexcept
+ : degrees{n % 360}
+ {
+ assert(invariant());
+ }
+
+ /* implicit */ constexpr operator auto() const noexcept
+ {
+ return degrees;
+ }
+};
+
+int main()
+{
+ static_assert(Angle{360} == 0, "");
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-02-18 4:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-18 4:57 C++ PATCH for c++/65985 (wrong error with constexpr ctor) Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).