Skip to content

Regression with lambda return type deduction #146063

Open
@AaronBallman

Description

@AaronBallman

The following used to compile without diagnostic in Clang 20.1:

template<class T, class U>
struct is_same {
  static constexpr bool value = false;
};
 
template<class T>
struct is_same<T, T> {
  static constexpr bool value = true;
};

template <typename T, int N>
struct A {
      static_assert([]() constexpr { // error: value of type 'void' is not contextually convertible to 'bool'
        if constexpr (is_same<T, int>::value)
          return true;
        else
          return (10 != N);
      }());
};                                                                                                                                            
int f1() {
    if constexpr (false) {
        A<int, 256> a;
    }
    return 0;
} 

but now gives an error on trunk: https://godbolt.org/z/fd5WY4xhY

Note, if you remove the if constexpr (false) from f1(), then the code compiles. If you add -> bool to the lambda, the code also compiles.

The code compiles without diagnostics in GCC, MSVC, and EDG.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++17clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationlambdaC++11 lambda expressionsregressionrejects-valid

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions