https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118144
Bug ID: 118144
Summary: Off-by-one error in expression mangling of parameter
reference in lambda
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hstong at ca dot ibm.com
Target Milestone: ---
According to the Itanium C++ ABI, the expression mangling for a function
parameter involves a number `L` where `L` is zero when referencing a parameter
of the current function declarator after the parameter declaration clause.
In the case where `L` is zero, the parameter reference is represented with a
prefix of `fp`.
Consider the following:
```
inline auto f() {
return []<typename T>(T p, auto (*)(T q)->decltype(p)) {};
}
void g() { throw f(); }
```
GCC generates `Z1fvEUlTyT_PFDtfp_ES_EE_` for the typeinfo string for the
closure type.
The `fp` in that string means `decltype(q)` _not_ `decltype(p)`.
Online compiler link: https://godbolt.org/z/Y6E117vfW
On a related note, with `decltype(q)` (as in the following) GCC seems to thinks
that the value of `L` is (uint64_t)-1 (generating
"Z1fvEUlTyT_PFDtfL18446744073709551614p_ES_EE_"):
```
inline auto f() {
return []<typename T>(T p, auto (*)(T q)->decltype(q)) {};
}
void g() { throw f(); }
```
### SOURCE (<stdin>)
inline auto f() {
return []<typename T>(T p, auto (*)(T q)->decltype(p)) {};
}
void g() { throw f(); }
### COMPILER INVOCATION
g++ -std=c++20 -xc++ - -S -o -
### ACTUAL COMPILER OUTPUT (partial)
_ZTSZ1fvEUlTyT_PFDtfp_ES_EE_:
.string "Z1fvEUlTyT_PFDtfp_ES_EE_"
### EXPECTED COMPILER OUTPUT (partial)
_ZTSZ1fvEUlTyT_PFDtfL0p_ES_EE_:
.string "Z1fvEUlTyT_PFDtfL0p_ES_EE_"
### COMPILER VERSION INFO (g++ -v)
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/15.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.0 20241219 (experimental) (GCC)