diff options
author | Da Xie <xxie_xd@163.com> | 2025-03-02 14:45:11 +0800 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2025-03-05 11:11:22 -0500 |
commit | 7439febd94368f42bc46885224e22d2f135fedb2 (patch) | |
tree | 238f5ba27d7e72c908336e7bb73b2f2254e72b26 | |
parent | ff505948631713d8c62523005059b10e25343617 (diff) | |
download | gcc-7439febd94368f42bc46885224e22d2f135fedb2.zip gcc-7439febd94368f42bc46885224e22d2f135fedb2.tar.gz gcc-7439febd94368f42bc46885224e22d2f135fedb2.tar.bz2 |
c++: Check invalid use of constrained auto with trailing return type [PR100589]
Add check for constrained auto type specifier in function declaration or
function type declaration with trailing return type. Issue error if such
usage is detected.
Test file renamed, and added a new test for type declaration.
Successfully bootstrapped and regretested on x86_64-pc-linux-gnu:
Added 6 passed and 4 unsupported tests.
PR c++/100589
gcc/cp/ChangeLog:
* decl.cc (grokdeclarator): Issue an error for a declarator with
constrained auto type specifier and trailing return types. Include
function names if available.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/concepts-pr100589.C: New test.
Signed-off-by: Da Xie <xxie_xd@163.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r-- | gcc/cp/decl.cc | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp2a/concepts-pr100589.C | 9 |
2 files changed, 22 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 9ca8c6c..337ee65 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -14037,6 +14037,19 @@ grokdeclarator (const cp_declarator *declarator, "invalid use of %<decltype(auto)%>"); return error_mark_node; } + else if (is_constrained_auto (type)) + { + if (funcdecl_p) + error_at (typespec_loc, + "%qs function with trailing return type " + "has constrained %<auto%> type specifier " + "rather than plain %<auto%>", + name); + else + error_at (typespec_loc, + "invalid use of constrained %<auto%> type"); + return error_mark_node; + } tree tmpl = CLASS_PLACEHOLDER_TEMPLATE (auto_node); if (!tmpl) if (tree late_auto = type_uses_auto (late_return_type)) diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr100589.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr100589.C new file mode 100644 index 0000000..918ba50 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr100589.C @@ -0,0 +1,9 @@ +// PR c++/100589 +// { dg-do compile { target c++20 } } + +template<class T> +concept false_concept = false; + +false_concept auto f() -> int; // { dg-error "'f' \[^\r\n\]* trailing return type has constrained 'auto'" } + +using type = false_concept auto() -> int; // { dg-error "invalid use of constrained 'auto' type" } |