mitaki28 / vscode-clang

Completion and Diagnostic for C/C++/Objective-C using Clang
MIT License
128 stars 24 forks source link

Not recognize C++11 lambda expression #31

Closed renkun-ken closed 8 years ago

renkun-ken commented 8 years ago

VSCode: 1.5.2 OS: Ubuntu 16.04.1 Extension: 0.2.1

I'm writing C++ 11 code and use lambda in my code. The following code is a simple example:

#include <iostream>

int main(int argc, char** argv)
{
    std::cout << "hello, world!" << std::endl;
    const int x = 0;
    const auto f = [&x](int i) { return x + i; };
    std::cout << f(10) << std::endl;
    return 0;
}

The code compiles perfectly with gcc and clang but in VSCode it produces the following warnings and errors:

  1. 'auto' type specifier is a C++11 extension [-Wc++11-extension](7, 11)
  2. expected expression (7, 20)

Below is a screenshot of this:

main cpp - cpptest - visual studio code_088

san-chang commented 8 years ago

It's work good for me :

VSCode: 1.5.2 OS: Ubuntu 16.04.1 Extension: 0.2.1

  • same code

could you please show me your config for C/C++ Clang?

It's mine:

// Compiler options for C (e.g. ['-std=c99'])
"clang.cflags": ["-std=c99"],

// Compiler options for C++ (e.g. ['-std=c++11'])
"clang.cxxflags": ["-std=c++11"],

check if you set -std=c++11 for your clang.cxxflags in "user settings" or "workspace settings"

renkun-ken commented 8 years ago

Thanks! With "clang.cxxflags": ["-std=c++11"], it works for me now.

Ridge2 commented 6 years ago

Or you can just type: g++ main.cpp -Wall -std=c++0x -o main Then: ./main to run the program.