PR c++/90736 - bogus error with alignof.
authorMarek Polacek <polacek@redhat.com>
Wed, 12 Jun 2019 20:17:36 +0000 (20:17 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 12 Jun 2019 20:17:36 +0000 (20:17 +0000)
* constexpr.c (adjust_temp_type): Use cv_unqualified type.

* g++.dg/cpp0x/alignof5.C: New test.

From-SVN: r272217

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/alignof5.C [new file with mode: 0644]

index 5e8fd69487d1ccc1ca0c21c3c3e870c238d974e0..90a7b2a87fdc8c91f34c66ed291d296f6bafb173 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-12  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/90736 - bogus error with alignof.
+       * constexpr.c (adjust_temp_type): Use cv_unqualified type.
+
 2019-06-11  Matthew Beliveau  <mbelivea@redhat.com>
 
        PR c++/90449 - add -Winaccessible-base option.
index a2f29694462326495309d56440354d1feb30a1d4..60cfafce1f2aa10c4235c21b1538a701170196a7 100644 (file)
@@ -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
index 3af2f4e92ba6aa0a07398722bd24b6731ba31b83..ebc738bfc05db94af0cffab00b1fa1e4933590d6 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-12  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/90736 - bogus error with alignof.
+       * g++.dg/cpp0x/alignof5.C: New test.
+
 2019-06-12  Dimitar Dimitrov  <dimitar@dinux.eu>
 
        * 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 (file)
index 0000000..09354d3
--- /dev/null
@@ -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;