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

Falsely flagged "expression must have a constant value" for std::numbers #12810

Open
alephpiece opened this issue Oct 6, 2024 · 0 comments
Open
Labels
bug investigate: repro This issue's repro steps needs to be investigated/confirmed Language Service

Comments

@alephpiece
Copy link

alephpiece commented Oct 6, 2024

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

image

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.

@sean-mcmanus sean-mcmanus added bug Language Service investigate: repro This issue's repro steps needs to be investigated/confirmed labels Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug investigate: repro This issue's repro steps needs to be investigated/confirmed Language Service
Projects
Status: No status
Development

No branches or pull requests

2 participants