https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71222

            Bug ID: 71222
           Summary: [concepts] ill-formed code taking the address of a
                    function concept not rejected
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tom at honermann dot net
                CC: andrew.n.sutton at gmail dot com, asutton at gcc dot gnu.org
  Target Milestone: ---

I believe the following code is ill-formed though I was unable to find
normative text in N4553 that explicitly makes it such.  The following
non-normative note in § 7.1.7p5 [dcl.spec.concept] suggests the intent for this
code to be ill-formed:

[Note: Return type deduction requires the instantiation of the function
definition, but concept definitions are not instantiated; they are normalized
(14.10.2). — end note]

gcc 7.0.0 (r236423) currently accepts this code, though a link error occurs
when linking an executable due to the reference to the uninstantiated FC<int>
function concept.  Note that directly invoking the function concept would
produce no errors since the result is evaluated at compile time; only taking
the address and later attempting to invoke the function is ill-formed.

$ cat t.cpp
template<typename T>
concept bool FC() { return true; }
int main() {
    auto fc = &FC<int>;
    fc();
}

$ svn info
Path: .
Working Copy Root Path: /home/tom/src/gcc-trunk
URL: svn://gcc.gnu.org/svn/gcc/trunk
Relative URL: ^/trunk
Repository Root: svn://gcc.gnu.org/svn/gcc
Repository UUID: 138bc75d-0d04-0410-961f-82ee72b054a4
Revision: 236427
Node Kind: directory
Schedule: normal
Last Changed Author: uros
Last Changed Rev: 236423
Last Changed Date: 2016-05-18 15:15:22 -0400 (Wed, 18 May 2016)

$ g++ --version
g++ (GCC) 7.0.0 20160518 (experimental)
...

$ g++ -c -std=c++1z -fconcepts t.cpp; echo $?
0

$ g++ -std=c++1z -fconcepts t.o -o t
t.o: In function `main':
t.cpp:(.text+0xc): undefined reference to `bool FC<int>()'
collect2: error: ld returned 1 exit status

Reply via email to