llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.06k stars 11.98k forks source link

Unexpected warning for pack indexing #112931

Open breese opened 3 weeks ago

breese commented 3 weeks ago

Suppose we use the feature test macro to only use pack indexing when available

template <std::size_t N, typename... Args>
constexpr auto my_element(Args... args) {
#if __cpp_pack_indexing >=  202311L
  return args...[N];
#else
  // Do something else
#endif
}

A compiler warning is emitted when compiling for C++23 or earlier

<source>:13:16: warning: pack indexing is a C++2c extension [-Wc++26-extensions]
   13 |         return args...[N];
      |                ^
1 warning generated.
llvmbot commented 3 weeks ago

@llvm/issue-subscribers-clang-frontend

Author: Bjørn Reese (breese)

Suppose we use the feature test macro to only use pack indexing when available ``` template <std::size_t N, typename... Args> constexpr auto my_element(Args... args) { #if __cpp_pack_indexing >= 202311L return args...[N]; #else // Do something else #endif } ``` A compiler warning is emitted when compiling for C++23 or earlier ``` <source>:13:16: warning: pack indexing is a C++2c extension [-Wc++26-extensions] 13 | return args...[N]; | ^ 1 warning generated. ```
zwuis commented 3 weeks ago

Similar issue: #109311.

cor3ntin commented 3 weeks ago

right, the feature test macro is set in all language modes because the feature is supported as an extension in all language modes