Skip to content

[Clang] constexpr variables wrongfully treated as captures in certain lambdas #120503

Open
@yuxuanchen1997

Description

@yuxuanchen1997

Clang currently rejects the following program by saying "error: variable 'XXXcap' cannot be implicitly captured in a lambda with no capture-default specified"

template <typename...>
struct tag_t {};

template <auto...>
struct vtag_t {};

template <auto... V>
inline constexpr vtag_t<V...> vtag{};

template <typename T>
constexpr bool alt = true;

template <typename = void>
auto vtag_safety_of_non_stored_args() {
  return []<typename T>(tag_t<T>) {
    return vtag<[]() {
      constexpr bool XXXcap = alt<T>;
      if constexpr (XXXcap) {
        return vtag<>;
      } else {
        return vtag<XXXcap>;
      }
    }>;
  }(tag_t<int>{});
}

void check() {
  vtag_safety_of_non_stored_args();
}

This seems wrong. As XXXcap here is not a capture. GCC and MSVC seem to have no problem with this.

See compiler explorer: https://godbolt.org/z/7rqcfGe7x

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"constexprAnything related to constant evaluationdiverges-from:edgDoes the clang frontend diverge from edg compilerdiverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issuelambdaC++11 lambda expressions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions