]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: fix pretty printing of 'alignof' vs '__alignof__' [PR85979]
authorPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 16:10:39 +0000 (12:10 -0400)
committerPatrick Palka <ppalka@redhat.com>
Sun, 7 May 2023 16:10:39 +0000 (12:10 -0400)
PR c++/85979

gcc/cp/ChangeLog:

* cxx-pretty-print.cc (cxx_pretty_printer::unary_expression)
<case ALIGNOF_EXPR>: Consider ALIGNOF_EXPR_STD_P.
* error.cc (dump_expr) <case ALIGNOF_EXPR>: Likewise.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/alignof4.C: New test.

gcc/cp/cxx-pretty-print.cc
gcc/cp/error.cc
gcc/testsuite/g++.dg/diagnostic/alignof4.C [new file with mode: 0644]

index 950295effc632e42b1e47efef93944ace8fd9715..4b547c77ef4aa8443f21c6bacc3f40d8a26f7274 100644 (file)
@@ -844,7 +844,12 @@ cxx_pretty_printer::unary_expression (tree t)
       /* Fall through  */
 
     case ALIGNOF_EXPR:
-      pp_cxx_ws_string (this, code == SIZEOF_EXPR ? "sizeof" : "__alignof__");
+      if (code == SIZEOF_EXPR)
+       pp_cxx_ws_string (this, "sizeof");
+      else if (ALIGNOF_EXPR_STD_P (t))
+       pp_cxx_ws_string (this, "alignof");
+      else
+       pp_cxx_ws_string (this, "__alignof__");
       pp_cxx_whitespace (this);
       if (TREE_CODE (t) == SIZEOF_EXPR && SIZEOF_EXPR_TYPE_P (t))
        {
index 1cfa4f1a2401e6be65162bac6ff771d7d1c29993..9b967ce409db5c3d387a9eb6aa31a90a28fc6479 100644 (file)
@@ -2840,11 +2840,10 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags)
     case ALIGNOF_EXPR:
       if (TREE_CODE (t) == SIZEOF_EXPR)
        pp_cxx_ws_string (pp, "sizeof");
+      else if (ALIGNOF_EXPR_STD_P (t))
+       pp_cxx_ws_string (pp, "alignof");
       else
-       {
-         gcc_assert (TREE_CODE (t) == ALIGNOF_EXPR);
-         pp_cxx_ws_string (pp, "__alignof__");
-       }
+       pp_cxx_ws_string (pp, "__alignof__");
       op = TREE_OPERAND (t, 0);
       if (PACK_EXPANSION_P (op))
        {
diff --git a/gcc/testsuite/g++.dg/diagnostic/alignof4.C b/gcc/testsuite/g++.dg/diagnostic/alignof4.C
new file mode 100644 (file)
index 0000000..f6fc5c3
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/85979
+// { dg-do compile { target c++11 } }
+
+template<int N> struct A { };
+
+template<class T>
+void f(A<alignof(T)>) { }
+
+#if __cpp_concepts
+template<class T>
+void g() requires (alignof(T) == 0);
+#endif
+
+int main() {
+  f<int>(); // { dg-error "no match" }
+#if __cpp_concepts
+  g<int>(); // { dg-error "no match" "" { target c++20 } }
+#endif
+}
+
+// { dg-bogus "__alignof__" "" { target *-*-* } 0 }