From: Patrick Palka Date: Sun, 7 May 2023 16:10:39 +0000 (-0400) Subject: c++: fix pretty printing of 'alignof' vs '__alignof__' [PR85979] X-Git-Tag: basepoints/gcc-15~9575 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9777f1b56f2794ff6cbbbd69ca588747d8ccf67;p=thirdparty%2Fgcc.git c++: fix pretty printing of 'alignof' vs '__alignof__' [PR85979] PR c++/85979 gcc/cp/ChangeLog: * cxx-pretty-print.cc (cxx_pretty_printer::unary_expression) : Consider ALIGNOF_EXPR_STD_P. * error.cc (dump_expr) : Likewise. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/alignof4.C: New test. --- diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc index 950295effc63..4b547c77ef4a 100644 --- a/gcc/cp/cxx-pretty-print.cc +++ b/gcc/cp/cxx-pretty-print.cc @@ -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)) { diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 1cfa4f1a2401..9b967ce409db 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -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 index 000000000000..f6fc5c315634 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/alignof4.C @@ -0,0 +1,21 @@ +// PR c++/85979 +// { dg-do compile { target c++11 } } + +template struct A { }; + +template +void f(A) { } + +#if __cpp_concepts +template +void g() requires (alignof(T) == 0); +#endif + +int main() { + f(); // { dg-error "no match" } +#if __cpp_concepts + g(); // { dg-error "no match" "" { target c++20 } } +#endif +} + +// { dg-bogus "__alignof__" "" { target *-*-* } 0 }