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

Template Variable Specialization Error: "variable xx has already been initialized" #3110

Closed
Zehua-Chen opened this issue Jan 29, 2019 · 7 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Milestone

Comments

@Zehua-Chen
Copy link

Type: LanguageService

Describe the bug

  • OS and Version: macOS 10.14.12
  • VS Code Version: 1.30.2
  • C/C++ Extension Version: 0.21.0
  • Other extensions you installed (and if the issue persists after disabling them):
    • C#
    • C# XML Documentation
    • CMake
    • Debugger for Unity
    • LaTeX Workshop
    • One Dark Pro
    • Pola Code
    • Verilog HDL/SystemVerilog
    • vscode-icons
    • x86 and x86_64 Assembly
  • A clear and concise description of what the bug is.

In the json parser that I am working on, I am using template variables as a part of my parser so that my parser would work with all types of chars in C++. The file that's causing the problem looks like the following snippet, but with a lot more template variables.

template<typename CharT>
inline constexpr CharT beginObject{};

template<>
inline constexpr char beginObject<char>{ '{' };

The clang++ compiler that I have on my mac (Apple LLVM version 10.0.0 (clang-1000.11.45.5)) compiles the code just fine, but vs code produces the following error:

variable "beginObject [with CharT=char]" has already been initialized

To Reproduce

  1. Set settings.json as follows
{
    "C_Cpp.default.cppStandard": "c++17"
}
  1. Create a main.cpp file;
  2. Copy and paste the following into the main file
// #include "gtest/gtest.h"
#include <iostream>

template<typename CharT>
CharT letter{};

template<>
char letter<char>{ 'a' };

int main(int argc, char **argv)
{
    std::cout << letter<char> << std::endl;
    // testing::InitGoogleTest(&argc, argv);
    // return RUN_ALL_TESTS();
    return 0;
}
  1. After the red flame goes off, the error should occur;
  2. To compile, use the following compiler flags (clang)
-std=c++17

(The actual project file that's causing the error looks very similar to this, but with a lot more template variables used in the json parser and does not have the main function. I am happy to provide the source code if needed.)

Expected behavior

There should be no errors from the plugin, as the compiler compiles the code just fine.

Screenshots

screen shot 2019-01-29 at 00 31 59

screen shot 2019-01-29 at 00 32 50

Additional context

@YassinMahmoudEl-Zouhery

is there any issue

@Zehua-Chen
Copy link
Author

Yes, the plugin is throwing a syntax error when the compiler does not.

@bobbrow
Copy link
Member

bobbrow commented Jan 29, 2019

@sean-mcmanus this looks like a bug we had in the past. Did we get a fix for it yet?

@sean-mcmanus
Copy link
Contributor

@sean-mcmanus sean-mcmanus added Visual Studio Inherited from Visual Studio and removed parser labels Feb 13, 2019
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Apr 4, 2019
@sean-mcmanus sean-mcmanus added this to the April 2019 milestone Apr 4, 2019
@sean-mcmanus
Copy link
Contributor

The fix for this incorrect IntelliSense error is in the latest Insiders version of the extension: https://github.com/Microsoft/vscode-cpptools/releases/tag/0.22.2-insiders

@Zehua-Chen
Copy link
Author

Thanks!

@github-actions github-actions bot locked and limited conversation to collaborators Oct 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Projects
None yet
Development

No branches or pull requests

4 participants