Skip to content

Wrong error about not capturing an already local variable #61029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JohelEGP opened this issue Feb 27, 2023 · 2 comments · May be fixed by #107942
Open

Wrong error about not capturing an already local variable #61029

JohelEGP opened this issue Feb 27, 2023 · 2 comments · May be fixed by #107942
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts constexpr Anything related to constant evaluation lambda C++11 lambda expressions

Comments

@JohelEGP
Copy link

The original code from #57958 still fails.
See https://godbolt.org/z/MbYYYKfv1.

#include <type_traits>

template<auto F> concept constant_invocable = requires { typename std::integral_constant<int, (F(), 0)>; };

template<class T>
constexpr bool C =
  [](auto) {
    return not constant_invocable<[]() {
      T v;
      (void)T{v};
    }>;
  }(0);

static_assert(C<int>);
<source>:10:15: warning: variable 'v' is uninitialized when used here [-Wuninitialized]
      (void)T{v};
              ^
<source>:14:15: note: in instantiation of variable template specialization 'C<int>' requested here
static_assert(C<int>);
              ^
<source>:9:10: note: initialize the variable 'v' to silence this warning
      T v;
         ^
          = 0
<source>:10:15: error: variable 'v' cannot be implicitly captured in a lambda with no capture-default specified
      (void)T{v};
              ^
<source>:7:3: note: in instantiation of function template specialization '(anonymous class)::operator()<int>' requested here
  [](auto) {
  ^
<source>:14:15: note: in instantiation of variable template specialization 'C<int>' requested here
static_assert(C<int>);
              ^
<source>:9:9: note: 'v' declared here
      T v;
        ^
<source>:8:35: note: lambda expression begins here
    return not constant_invocable<[]() {
                                  ^
<source>:8:36: note: capture 'v' by value
    return not constant_invocable<[]() {
                                   ^
                                   v
<source>:8:36: note: capture 'v' by reference
    return not constant_invocable<[]() {
                                   ^
                                   &v
<source>:8:36: note: default capture by value
    return not constant_invocable<[]() {
                                   ^
                                   =
<source>:8:36: note: default capture by reference
    return not constant_invocable<[]() {
                                   ^
                                   &
1 warning and 1 error generated.
Compiler returned: 1
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed new issue labels Feb 27, 2023
@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2023

@llvm/issue-subscribers-clang-frontend

@zyn0217
Copy link
Contributor

zyn0217 commented Oct 8, 2024

Would be fixed by #107942.

@zyn0217 zyn0217 linked a pull request Oct 8, 2024 that will close this issue
@zyn0217 zyn0217 added the concepts C++20 concepts label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts constexpr Anything related to constant evaluation lambda C++11 lambda expressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants