Bug 85846 - [Concepts] Concept as value in initializer: bogus declared-as-implicit-template error
Summary: [Concepts] Concept as value in initializer: bogus declared-as-implicit-templa...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: 11.3
Assignee: Patrick Palka
URL:
Keywords: rejects-valid
: 99923 (view as bug list)
Depends on:
Blocks: concepts
  Show dependency treegraph
 
Reported: 2018-05-20 00:51 UTC by Hubert Tong
Modified: 2022-02-02 02:08 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 10.0
Last reconfirmed: 2019-10-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hubert Tong 2018-05-20 00:51:38 UTC
When a concept with a non-type prototype parameter is used as a variable
template in a context where the most vexing parse would prefer interpretation
of an ambiguous construct as naming a type, GCC produces a bogus message
about creating an implicit non-function template.

In the case below, either f is being declared as a function, or Foo<> cannot
be considered a type (and therefore, it cannot cause formation of an implicit
template through the abbreviated function template mechanism).

### SOURCE (<stdin>):
template <int = 0> concept bool Foo = true;
bool f(Foo<>);


### COMPILER INVOCATION:
g++ -fsyntax-only -xc++ -fconcepts -


### ACTUAL OUTPUT:
<stdin>:2:6: error: non-function 'f' declared as implicit template


### EXPECTED OUTPUT:
(Clean compile).


### COMPILER VERSION INFO (g++ -v):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head --enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl --enable-checking=release --disable-nls --enable-lto LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
gcc version 9.0.0 20180518 (experimental) (GCC)
Comment 1 GCC Commits 2021-11-09 14:11:13 UTC
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:a22d910305a5232694ff48ead37a7f53e46b7202

commit r12-5053-ga22d910305a5232694ff48ead37a7f53e46b7202
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Nov 9 09:09:43 2021 -0500

    c++: bogus error w/ tentative type parse of concept-id [PR98394]
    
    Here when tentatively parsing the if condition as a declaration, we try
    to treat C<1> as the start of a constrained placeholder type, which we
    quickly reject because C doesn't accept a type as its first argument.
    But since we're parsing tentatively, we shouldn't emit an error in this
    case.
    
    In passing, also fix PR85846 by only overriding 'tentative' to false when
    given a concept-name, and not also when given a concept-id that has an empty
    argument list.
    
            PR c++/98394
            PR c++/85846
    
    gcc/cp/ChangeLog:
    
            * parser.c (cp_parser_placeholder_type_specifier): Declare
            static.  Don't override tentative to false when tmpl is a
            concept-id with empty argument list.  Don't emit a "does not
            constrain a type" error when tentative.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/concepts-pr98394.C: New test.
            * g++.dg/cpp2a/concepts-pr85846.C: New test.
Comment 2 GCC Commits 2021-12-15 19:55:21 UTC
The releases/gcc-11 branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:a94867f67e0b48ba53691f1d5f43f5c7d60adecb

commit r11-9388-ga94867f67e0b48ba53691f1d5f43f5c7d60adecb
Author: Patrick Palka <ppalka@redhat.com>
Date:   Tue Nov 9 09:09:43 2021 -0500

    c++: bogus error w/ tentative type parse of concept-id [PR98394]
    
    Here when tentatively parsing the if condition as a declaration, we try
    to treat C<1> as the start of a constrained placeholder type, which we
    quickly reject because C doesn't accept a type as its first argument.
    But since we're parsing tentatively, we shouldn't emit an error in this
    case.
    
    In passing, also fix PR85846 by only overriding 'tentative' to false when
    given a concept-name, and not also when given a concept-id that has an empty
    argument list.
    
            PR c++/98394
            PR c++/85846
    
    gcc/cp/ChangeLog:
    
            * parser.c (cp_parser_placeholder_type_specifier): Declare
            static.  Don't override tentative to false when tmpl is a
            concept-id with empty argument list.  Don't emit a "does not
            constrain a type" error when tentative.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp2a/concepts-pr98394.C: New test.
            * g++.dg/cpp2a/concepts-pr85846.C: New test.
    
    (cherry picked from commit a22d910305a5232694ff48ead37a7f53e46b7202)
Comment 3 Patrick Palka 2021-12-15 19:56:26 UTC
Fixed for GCC 11.3/12.
Comment 4 Patrick Palka 2022-02-02 02:08:51 UTC
*** Bug 99923 has been marked as a duplicate of this bug. ***