From 72b091f736addb1ca458e7766dc4547fde331d28 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Wed, 12 Jun 2019 20:17:36 +0000 Subject: [PATCH] PR c++/90736 - bogus error with alignof. * constexpr.c (adjust_temp_type): Use cv_unqualified type. * g++.dg/cpp0x/alignof5.C: New test. From-SVN: r272217 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/constexpr.c | 4 +++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/alignof5.C | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alignof5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5e8fd69487d..90a7b2a87fd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2019-06-12 Marek Polacek + + PR c++/90736 - bogus error with alignof. + * constexpr.c (adjust_temp_type): Use cv_unqualified type. + 2019-06-11 Matthew Beliveau PR c++/90449 - add -Winaccessible-base option. diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index a2f29694462..60cfafce1f2 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1318,7 +1318,9 @@ adjust_temp_type (tree type, tree temp) if (TREE_CODE (temp) == EMPTY_CLASS_EXPR) return build0 (EMPTY_CLASS_EXPR, type); gcc_assert (scalarish_type_p (type)); - return cp_fold_convert (type, temp); + /* Now we know we're dealing with a scalar, and a prvalue of non-class + type is cv-unqualified. */ + return cp_fold_convert (cv_unqualified (type), temp); } /* If T is a CONSTRUCTOR, return an unshared copy of T and any diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3af2f4e92ba..ebc738bfc05 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-06-12 Marek Polacek + + PR c++/90736 - bogus error with alignof. + * g++.dg/cpp0x/alignof5.C: New test. + 2019-06-12 Dimitar Dimitrov * gcc.dg/builtin-apply2.c: Skip for PRU. diff --git a/gcc/testsuite/g++.dg/cpp0x/alignof5.C b/gcc/testsuite/g++.dg/cpp0x/alignof5.C new file mode 100644 index 00000000000..09354d3e1d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alignof5.C @@ -0,0 +1,6 @@ +// PR c++/90736 - bogus error with alignof. +// { dg-do compile { target c++11 } } + +constexpr int fn(const int b) { return b; } +constexpr int c = fn(alignof(int)); +alignas(c) char d; -- 2.30.2