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

            Bug ID: 92187
           Summary: [concepts] An abbreviated function template ignores
                    type constraint in some circumstances
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com
  Target Milestone: ---

The sample code below is compiled successfully by current trunk.

==========================
template <typename>
concept C = false;

C auto f(auto)
{
    return 42;
}

int main()
{
    return f(0);
}
==========================
cf. https://wandbox.org/permlink/BXPESMeiWSoUSmTn

According to C++ standard draft N4835 [dcl.type.auto.deduct] p.6,

> For a placeholder-type-specifier with a type-constraint, the 
> immediately-declared
> constraint of the type-constraint for the type deduced for the placeholder 
> shall
> be satisfied.

So I think that the code should be failed to compile.

Note that the codes below are failed to compile.

==========================
template <typename>
concept C = false;

// normal(non abbreviated) function template
template <typename T>
C auto f(T)
{
    return 42;
}

int main()
{
    return f(0);
}
==========================
cf. https://wandbox.org/permlink/j3HfbOv7PbOqSnhj

==========================
template <typename>
concept C = false;

// normal function
C auto f(int)
{
    return 42;
}

int main()
{
    return f(0);
}
==========================
cf. https://wandbox.org/permlink/blq6P4QgQdgEuPF9

==========================
template <typename>
concept C = false;

// trailing return type
auto f(auto) -> C auto
{
    return 42;
}

int main()
{
    return f(0);
}
==========================
cf. https://wandbox.org/permlink/JfV8QmbNnjZ4ranP

Reply via email to