Skip to content
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

C++26 Pack-indexing have BUG #91884

Closed
Mq-b opened this issue May 12, 2024 · 3 comments · Fixed by #91933
Closed

C++26 Pack-indexing have BUG #91884

Mq-b opened this issue May 12, 2024 · 3 comments · Fixed by #91933
Labels
c++26 clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@Mq-b
Copy link

Mq-b commented May 12, 2024

auto print(auto&&...args){
    [&]<std::size_t... idx>(std::index_sequence<idx...>){
        std::print("{} {} {} {}",args...[idx]...);
    }(std::make_index_sequence<sizeof...(args)>());
}

int main(){
    print(1,2,3,"🤣");
}

OK ! godbolt..

auto print(auto&&...args){
    [&]<std::size_t... idx>(std::index_sequence<idx...>){
        (std::print("{} ",args...[idx]), ...);
    }(std::make_index_sequence<sizeof...(args)>());
}

int main(){
    print(1,2,3,"🤣");
}

Error ! godbolt..

If changed to:

void print_one(auto& arg){
    std::print("{} ", arg);
}

void print(auto&&...args){
    [&]<std::size_t... idx>(std::index_sequence<idx...>){
        (::print_one<decltype((args...[idx]))>(args...[idx]), ...);
    }(std::make_index_sequence<sizeof...(args)>());
}

OK ! godbolt..

Seems to be moving out? But it doesn't matter. It's a BUG.

@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" c++26 and removed new issue labels May 12, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 12, 2024

@llvm/issue-subscribers-clang-frontend

Author: mq白 (Mq-b)

```cpp auto print(auto&&...args){ [&]<std::size_t... idx>(std::index_sequence<idx...>){ std::print("{} {} {} {}",args...[idx]...); }(std::make_index_sequence<sizeof...(args)>()); }

int main(){
print(1,2,3,"🤣");
}


OK ! [godbolt..](https://godbolt.org/z/3KWWjb39T)

```cpp
auto print(auto&amp;&amp;...args){
    [&amp;]&lt;std::size_t... idx&gt;(std::index_sequence&lt;idx...&gt;){
        (std::print("{} ",args...[idx]), ...);
    }(std::make_index_sequence&lt;sizeof...(args)&gt;());
}

int main(){
    print(1,2,3,"🤣");
}

Error ! godbolt..

If changed to:

void print_one(auto&amp; arg){
    std::print("{} ", arg);
}

void print(auto&amp;&amp;...args){
    [&amp;]&lt;std::size_t... idx&gt;(std::index_sequence&lt;idx...&gt;){
        (::print_one&lt;decltype((args...[idx]))&gt;(args...[idx]), ...);
    }(std::make_index_sequence&lt;sizeof...(args)&gt;());
}

OK ! godbolt..

Seems to be moving out? But it doesn't matter. It's a BUG.

@cor3ntin
Copy link
Contributor

@Sirraide didn't you look at something very similar recently?

cor3ntin added a commit to cor3ntin/llvm-project that referenced this issue May 13, 2024
Given `foo...[idx]` if idx is value dependent, the expression
is type dependent.

Fixes llvm#91885
Fixes llvm#91884
cor3ntin added a commit to cor3ntin/llvm-project that referenced this issue May 13, 2024
Given `foo...[idx]` if idx is value dependent, the expression
is type dependent.

Fixes llvm#91885
Fixes llvm#91884
@Sirraide
Copy link
Contributor

@Sirraide didn't you look at something very similar recently?

That was specifically about dependence of lambdas captures in lambdas with explicit object parameters that should have been dependent if the type of the explicit object parameter is.

mub-at-arm pushed a commit to mub-at-arm/llvm-project that referenced this issue May 16, 2024
…#91933)

Given `foo...[idx]` if idx is value dependent, the expression is type
dependent.

Fixes llvm#91885
Fixes llvm#91884
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++26 clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants