microsoft / microsoft/vscode-cpptools

VSCode reports 'converstion from "x" to "y" is invalid in constant-expression evalution', yet code builds fine

Open
#2,111 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Language Service Visual Studio
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Type: LanguageService

Describe the bug

  • OS and Version: Windows 10 build 17686
  • VS Code Version: 1.23.1
  • C/C++ Extension Version: 0.17.4
  • Other extensions you installed (and if the issue persists after disabling them): I have others extensions installed, but after disabling all of them except my theme (Railgun) and this addon, it still persists.
  • Description: VSCode reports an error for code that builds correctly.

To Reproduce
Steps to reproduce the behavior: (The default C++ properties were used)

  1. Clone the following gist: https://gist.github.com/sylveon/b63621297d566d06ab38bd5586eca0ed
  2. Open it in vscode
  3. Open main.cpp
  4. See red squiggles on CalculateHueGradient() call
  5. When hovering, you can read expression must have a constant value -- conversion from "float" to "unsigned short" is invalid in constant-expression evaluation

Expected behavior
No error, like msvc and clang do while building the snippet:

C:\Users\Charles\Git\TranslucentTB>cl test.cpp /EHsc
Microsoft (R) C/C++ Optimizing Compiler Version 19.14.26430 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
Microsoft (R) Incremental Linker Version 14.14.26430.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
C:\Users\Charles\Git\TranslucentTB>clang-cl --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

C:\Users\Charles\Git\TranslucentTB>clang-cl /EHsc test.cpp
(no output, meaning a successful compilation)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report by opening the linked gist in VS Code and inspecting the red squiggles on the CalculateHueGradient() call in main.cpp. Compare the language-service diagnostic with the successful MSVC and clang-cl builds shown in the issue; done means the valid conversion no longer produces an error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, vscode
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.