Diagnostics for C++ project fails to get the correct version of the standard being used
The Problem
Sometimes the C++ diagnostics plugin fails to obtain the correct C++ Version and displays warnings and errors inside the editor although the project actually builds fine.
I could swear that this also happened with source files. However I only was able to find a simple reproducible case involving header files. (So maybe my issue with source files was that in these cases meson didn't run correctly because of some syntax error and it took builder some time to reproduce the diagnostics. Just mentioning it here for the sake of completeness.)
How to reproduce
Create these three files:
meson.build
Note that I added the headers as extra_files
to the executable and that the default C++ version is set to C++17 for the whole project. So there is definitely a way of knowing the version that is presumably used for these headers.
project('cpp17', 'cpp', default_options: ['cpp_std=c++17'])
cpp17_src = [
'main.cpp'
]
cpp17_headers = [
'main.hpp'
]
executable('cpp17',
sources: cpp17_src,
extra_files: cpp17_headers,
install: true,
override_options : ['cpp_std=c++17']
)
main.cpp
#include <map>
#include <iostream>
#include <main.hpp>
int main()
{
std::map<int, int> some_map = {{0, 0}, {1, 1}};
for(auto [key, value] : some_map)
std::cout << key << "," << value << "\n";
return 0;
}
main.hpp
#include <map>
#include <iostream>
#ifndef MAIN_H
#define MAIN_H
int test()
{
std::map<int, int> some_map = {{0, 0}, {1, 1}};
for(auto [key, value] : some_map)
std::cout << key << "," << value << "\n";
return 0;
}
#endif //MAIN_H
Expected behaviour
No warnings (or errors) inside the editor. There shouldn't be any as the project builds flawlessly.
Actual behaviour
Inside the header file a warning is shown:
Despite the fact that meson reports this as a C++17 project:
$ meson introspect --buildoptions /home/user/.cache/gnome-builder/builddir_of_project | grep -o ".\{,10\}cpp_std.\{,20\}"
{"name": "cpp_std", "value": "c++17",
Conclusion
Now, I don't know if this qualifies as a bug, a missing feature or if I'm supposed to do something differently in my build file. But it really annoys me. Especially for larger projects. Would it be possible to implement this? And independently from that is there a way to work around it?
Thanks in advance.
Edit
Here is the verbose logging output of builder. I opened aforementioned project, commented and uncommented the relevant line of code to make sure the diagnostics are run again and closed builder.
gnome-builder -vvvv &>
builder-log.txt