microsoft / microsoft/vscode-cpptools
Intellisense incorrectly identifies pow() as a non-constexpr, which causes constexpr functions containing pow() to incorrectly show an error
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 1.7k
- Avg merge
- 14h 46m
- Merged PRs (30d)
- 61
Description
Environment
- OS and Version: Windows 11
- VS Code Version: v1.96.2
- C/C++ Extension Version: v1.22.11
- If using SSH remote, specify OS of remote machine: Running on Remote Explorer on Ubuntu 22.04 using g++ v11.4.0 and c++20
Bug Summary and Steps to Reproduce
Bug Summary:
We have a constexpr function that contains the math function pow(). This compiles fine on g++ however Intellisense shows an error, the error reported is "cannot call non-constexpr function "__builtin_powf" (declared implicitly)". However the code compiles cleanly and works as expected.
Steps to reproduce:
Simplified example
constexpr std::array<float, 256> gen_lut() {
std::array<float, 256> lut = {};
for (int i = 0; i < 256; ++i) {
lut[i] = std::pow((2f, static_cast<float>(i));
}
return lut;
}
constexpr auto linear_lut = gen_lut();
The error is reported under the gen_lut(); call in the last line.
Expected behavior:
Intellisense should not report an error. This is valid C++ that compiles on g++ 11.4
Configuration and Logs
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/local/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
"-std=c++20"
]
}
],
"version": 4
}
Other Extensions
No response
Additional context
This bug prevents our projects from reporting no error, which impacts development since it is difficult to notice during development when there is an actual bug and we don't notice later till the compilation fails.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the diagnostic with the reported gen_lut() example under the C++ extension's IntelliSense configuration, then compare IntelliSense's treatment of std::pow with g++ 11.4 in C++20 mode. Trace the pow() and constexpr analysis entry points; done means valid code no longer receives the false non-constexpr diagnostic while genuine errors remain reported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, typescript, vscode
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100