diff options
author | Patrick Palka <ppalka@redhat.com> | 2020-04-18 06:22:14 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2020-04-18 06:22:14 -0400 |
commit | e43b28ae7f09c0b7a30ab0dd976db761eeb1b0f9 (patch) | |
tree | 7f40923470b0d0449338419d8359f2e96011b3be | |
parent | c5bac7d127f288fd2f8a1f15c3f30da5903141c6 (diff) | |
download | gcc-e43b28ae7f09c0b7a30ab0dd976db761eeb1b0f9.zip gcc-e43b28ae7f09c0b7a30ab0dd976db761eeb1b0f9.tar.gz gcc-e43b28ae7f09c0b7a30ab0dd976db761eeb1b0f9.tar.bz2 |
c++: Abbreviated function template return type [PR92187]
When updating an auto return type of an abbreviated function template in
splice_late_return_type, we should also propagate PLACEHOLDER_TYPE_CONSTRAINTS
(and cv-qualifiers) of the original auto node.
gcc/cp/ChangeLog:
PR c++/92187
* pt.c (splice_late_return_type): Propagate cv-qualifiers and
PLACEHOLDER_TYPE_CONSTRAINTS from the original auto node to the new one.
gcc/testsuite/ChangeLog:
PR c++/92187
* g++.dg/concepts/abbrev5.C: New test.
* g++.dg/concepts/abbrev6.C: New test.
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/pt.c | 15 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/concepts/abbrev5.C | 15 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/concepts/abbrev6.C | 12 |
5 files changed, 50 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b89b6d8..45c422f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2020-04-18 Patrick Palka <ppalka@redhat.com> + + PR c++/92187 + * pt.c (splice_late_return_type): Propagate cv-qualifiers and + PLACEHOLDER_TYPE_CONSTRAINTS from the original auto node to the new one. + 2020-04-17 Patrick Palka <ppalka@redhat.com> PR c++/94483 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0a8ec31..9e39f46 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -29032,10 +29032,17 @@ splice_late_return_type (tree type, tree late_return_type) { tree idx = get_template_parm_index (*auto_node); if (TEMPLATE_PARM_LEVEL (idx) <= processing_template_decl) - /* In an abbreviated function template we didn't know we were dealing - with a function template when we saw the auto return type, so update - it to have the correct level. */ - *auto_node = make_auto_1 (TYPE_IDENTIFIER (*auto_node), true); + { + /* In an abbreviated function template we didn't know we were dealing + with a function template when we saw the auto return type, so update + it to have the correct level. */ + tree new_auto = make_auto_1 (TYPE_IDENTIFIER (*auto_node), false); + PLACEHOLDER_TYPE_CONSTRAINTS (new_auto) + = PLACEHOLDER_TYPE_CONSTRAINTS (*auto_node); + TYPE_CANONICAL (new_auto) = canonical_type_parameter (new_auto); + new_auto = cp_build_qualified_type (new_auto, TYPE_QUALS (*auto_node)); + *auto_node = new_auto; + } } return type; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e5d0d92..08bef53 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-04-18 Patrick Palka <ppalka@redhat.com> + + PR c++/92187 + * g++.dg/concepts/abbrev5.C: New test. + * g++.dg/concepts/abbrev6.C: New test. + 2020-04-17 Jeff Law <law@redhat.com> PR rtl-optimization/90275 diff --git a/gcc/testsuite/g++.dg/concepts/abbrev5.C b/gcc/testsuite/g++.dg/concepts/abbrev5.C new file mode 100644 index 0000000..de594b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/abbrev5.C @@ -0,0 +1,15 @@ +// PR c++/92187 +// { dg-do compile { target concepts } } + +template <typename> +concept C = false; + +C auto f(auto) +{ + return 42; // { dg-error "deduced return type" } +} + +void foo() +{ + f(0); +} diff --git a/gcc/testsuite/g++.dg/concepts/abbrev6.C b/gcc/testsuite/g++.dg/concepts/abbrev6.C new file mode 100644 index 0000000..862675e --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/abbrev6.C @@ -0,0 +1,12 @@ +// { dg-do compile { target concepts } } + +const auto &f(auto) +{ + static int n; + return n; +} + +void foo() +{ + f(5) = 0; // { dg-error "read-only" } +} |