vscode-cpptools
vscode-cpptools copied to clipboard
Falsely flagged "expression must have a constant value" for std::numbers
trafficstars
Environment
- OS and Version: Windows_NT x64 10.0.22631
- VS Code Version: 1.93.1
- C/C++ Extension Version: 1.21.6
- If using SSH remote, specify OS of remote machine: Ubuntu 22.04.4 LTS in WSL2
Bug Summary and Steps to Reproduce
Bug Summary:
The intellisense complains that expression must have a constant value when a constant expression from std::numbers is used in another constant expression.
Steps to reproduce:
#include <numbers>
int main() {
constexpr double pi_2 = std::numbers::pi / 2.;
return 0;
}
Expected behavior:
No error.
Configuration and Logs
Configuragions:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++-11",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Diagnostics:
-------- Diagnostics - 10/7/2024, 12:07:20 AM
Version: 1.21.6
Current Configuration:
{
"name": "Linux",
"includePath": [
"/home/one/experiments/vscode-intellisense-issue/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++-11",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "linux-gcc-x64",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"compilerPathInCppPropertiesJson": "/usr/bin/g++-11",
"mergeConfigurations": false,
"browse": {
"path": [
"/home/one/experiments/vscode-intellisense-issue/**",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
cpptools version (native): 1.21.6.0
Translation Unit Mappings:
[ /home/one/experiments/vscode-intellisense-issue/main.cpp - source TU]:
Translation Unit Configurations:
[ /home/one/experiments/vscode-intellisense-issue/main.cpp ]:
Process ID: 50136
Memory Usage: 25 MB
Compiler Path: /usr/bin/g++-11
Includes:
System Includes:
/usr/include/c++/11
/usr/include/x86_64-linux-gnu/c++/11
/usr/include/c++/11/backward
/usr/lib/gcc/x86_64-linux-gnu/11/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
Standard Version: c++20
IntelliSense Mode: linux-gcc-x64
Other Flags:
--g++
--gnu_version=110400
Total Memory Usage: 25 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 7073
Other Extensions
None
Additional context
If the constant is defined without potential narrowing, the intellisense works fine. For example,
template <typename T>
inline constexpr T pi_v = 3.141592653589793238462643383279502884;
inline constexpr double pi = pi_v<double>;
int main() {
constexpr double pi_2 = pi / 2.;
return 0;
}
Note that the definition in std::numbers is something like
template <typename T>
inline constexpr T pi_v = T(3.141592653589793238462643383279502884L);
inline constexpr double pi = pi_v<double>;
The narrowing conversion for the literal is definitely legal.
Hi @alephpiece . Thanks for reporting this. I've opened a bug (2285676) internally against the IntelliSense component shared with VS.