Skip to content

Clang doesn't SFINAE out constrained overload when substitution-failure happens in template-head #61824

@cjdb

Description

@cjdb

GCC test concepts-defarg2.C fails in Clang. I'm not sure if GCC should be accepting the original lines, but Clang gets suspicious when I uncomment my addition (which I don't think should be failing).

// PR c++/97052
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s

template<typename T, typename U = typename T::type>
concept C = true;

constexpr bool f(C auto) {
  return true;
}

// added by me
// constexpr bool f(auto) {
//   return true;
// }

static_assert(f(0));

C auto x = 0;

Diagnostics prior to uncommenting:

<source>:16:15: error: no matching function for call to 'f'
static_assert(f(0));
              ^
<source>:7:16: note: candidate template ignored: constraints not satisfied [with auto:1 = int]
constexpr bool f(C auto) {
               ^
<source>:4:44: note: because substituted constraint expression is ill-formed: type 'int' cannot be used prior to '::' because it has no members
template<typename T, typename U = typename T::type>
                                           ^
<source>:4:44: error: type 'int' cannot be used prior to '::' because it has no members
template<typename T, typename U = typename T::type>
                                           ^
note: in instantiation of default argument for 'C<int>' required here

Diagnostics after uncommenting:

<source>:4:44: error: type 'int' cannot be used prior to '::' because it has no members
template<typename T, typename U = typename T::type>
                                           ^
note: in instantiation of default argument for 'C<int>' required here

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!rejects-valid

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions