Skip to content

Intellisense won't allow __builtin_expect in ctor of constexpr value #2824

@tonyelewis

Description

@tonyelewis

Type: LanguageService

Thanks very much for all your work on this extension. I really love using both it and VSCode.

Strict Intellisense on this source code:

struct x {
   constexpr x(int val) {
      [[maybe_unused]] const auto mu = __builtin_expect( val, 0 );
   }
};

[[maybe_unused]] constexpr x x1{ 3 };

…puts a red-squiggle under the x1 on the last line, with mouseover message:

expression must have a constant value -- cannot call non-constexpr function "__builtin_expect" (declared implicitly)
constexpr x x1

…but GCC and Clang are happy with it:

g++     -Werror -Wall -Wextra -pedantic -std=c++17 -fsyntax-only a.cpp
clang++ -Werror -Wall -Wextra -pedantic -std=c++17 -fsyntax-only a.cpp

I've come across this through using the Microsoft GSL library. I can work-around the issue by adding a GSL_UNENFORCED_ON_CONTRACT_VIOLATION define in c_cpp_properties.json. But it'd be good to get this fixed in VSCode.

Repro steps:

  1. Open a folder
  2. Create and open a.cpp
  3. Paste in the above code
  4. Set strict Intellisense - full c_cpp_properties.json as follows…
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Context:

C/C++ for Visual Studio Code v0.20.1

Version: 1.29.0
Commit: 5f24c93878bd4bc645a4a17c620e2487b11005f9
Date: 2018-11-12T07:42:27.562Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

Ubuntu 18.04.1 LTS
Linux 4.15.0-39-generic #42-Ubuntu SMP Tue Oct 23 15:48:01 UTC 2018

Thanks again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Language ServiceVisual StudioInherited from Visual StudiobugfixedCheck the Milestone for the release in which the fix is or will be available.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions