Error in vscode but not in command line build

Hello,

I have this line of code

std::unique_ptr<char[]> buf(new char[size]);

In the PlatformIO IDE in vscode shows this error

'namespace "std" has no member "unique_ptr"'

However in command line builds (pio run) the code compiles fine without error.

Any ideas why the IDE is showing errors when the command line build is fine?

Could you provide a simple project to reproduce this issue?

Here is a sample project that reproduces the problem https://github.com/jeraymond/problem-project.

To reproduce:

  1. In vscode from PIO Home tab choose Open Project and select the problem-project directory.
  2. Click the checkbox to run PlatformIO: Build.

The PlatformIO: Build task succeeds. After running the build problem-project.cpp shows 4 errors in the IDE window.

ide errors

Running pio run from the command line also is okay and does not show any errors.

I’m running this on macOS High Sierra with PlatformIO 3.5.3a7, vscode 1.21.1, PlatformIO IDE 0.14.0.

I opened this same project in Atom and it did not show the same errors. I then generated the project file for CLion, opened it and it does show the error again.

Perhaps this is a path issue when generating the project files.

My platformio.ini has

[env:huzzah]
build_flags = -Wl,-Teagle.flash.4m.ld
platform = espressif8266
board = huzzah
framework = arduino
monitor_baud=115200

In which headers would I expected std::unique_ptr to be defined for this configuration? How do the project file paths differ than the command line pio run builds?

It looks like the build happens with toolchain-xtensa. The PlatformIO IDE uses clang for code completion. I found that the memory header in the xtensa toolchain includes bits/unique_ptr.h for the implementation. In that header I see _GLIBXX pragmas (such as _GLIBCXX_VISIBILITY(default)).

Could it be that these headers work with xtensa-lx106-elf-g++ but not Clang?

HI, the same happened to me, after the last update of vscode or platformio, I dont know which one because being honest I didnt read the message, it stoped recognizing std::bind, std::unique_ptr or the type WiFiEventHandler which I am guessing is from ESP8266WiFi.h, but the trick is in the c_cpp_properties.json file, modify the define __cplusplus and set it to 201103L being the result “__cplusplus=201103L” so it will use the c++11 standard, that worked for me and holefully for you too.

Sorry for the english, not native.

Have a good day.

Thanks! That fixes the issue for me. I’ve filed bug for this problem pio generates wrong __cplusplus value in c_cpp_properties.json resulting in IDE build errors for std::unique_ptr in Visual Studio Code · Issue #1546 · platformio/platformio-core · GitHub.

Thanks for opening the bug. You are right, when re opening the project the value gets rewritten and the annoying problem returns, I hope it gets fixed soon.

Have a good day.

Please open PIO IDE Terminal and type pio upgrade --dev. Restart IDE.

Did the upgrade and works OK now,
Regards.