Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » CodeAnalyzer errors - c++17 - tuple and structured bindings(The CodeAnalyzer gives errors (invalid overload, field could not be resolved) but code compiles fine with gcc)
CodeAnalyzer errors - c++17 - tuple and structured bindings [message #1849027] Wed, 29 December 2021 20:45 Go to next message
Eagle OneTwoThree is currently offline Eagle OneTwoThreeFriend
Messages: 1
Registered: December 2021
Junior Member
Hi,
The following code compiles fine with g++ (GCC) 7.3.0, but in Eclipse (Eclipse IDE for C/C++ Developers (includes Incubating components) Version: 2021-12 (4.22.0) Build id: 20211202-1639) I get errors from the code analyzer.

In Eclipse I set this up as a c++ linux project, and I set the C++ compiler "dialect" to ISO C++17.

Build command:
make all 
Building file: ../src/a.cpp
Invoking: GCC C++ Compiler
g++ -std=c++17 -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/a.d" -MT"src/a.o" -o "src/a.o" "../src/a.cpp"
Finished building: ../src/a.cpp
 
Building target: a
Invoking: GCC C++ Linker
g++  -o "a"  ./src/a.o   
Finished building target: a



File b.h:
#include <tuple>

typedef int I;
struct S {
	int m;
};

std::tuple<I const, S const , int const > getTuple();
std::tuple<I const, S const > get2Tuple();
std::tuple<S const , int const > get3Tuple();


File a.cpp:
#include "b.h"
#include <iostream>

int main() {
	{
		auto [first, second, third] = getTuple();
		std::cout << first << std::endl; // /a/src	line 7: std::endl is underlined in red by code analyzer
		std::cout << second.m << std::endl;
		std::cout << third << std::endl;
	}
	{
		auto [first, second] = get2Tuple();
		std::cout << first << std::endl; // /a/src	line 13: std::endl is underlined in red by code analyzer
		std::cout << second.m << std::endl;
	}
	{
		auto [second, third] = get3Tuple();
		std::cout << second.m << std::endl; // /a/src	line 18:  m and std::endl is underlined in red by code analyzer
		std::cout << third << std::endl;
	}
	return 0;
}

std::tuple<I const, S const , int const > getTuple()
{
	I first = 1;
	S second;
	second.m = 2;
	int third = 3;
    return std::tuple<I const, S const , int const >(first, second, third);
}

std::tuple<I const, S const> get2Tuple()
{
	I first = 1;
	S second;
	second.m = 2;
    return std::tuple<I const, S const>(first, second);
}


std::tuple<S const , int const > get3Tuple()
{
	S second;
	second.m = 2;
	int third = 3;
    return std::tuple<S const , int const >(second, third);
}


These are the errors I get - and rebuilding the index does not fix it:
Invalid overload of 'std::endl'	a.cpp	/a/src	line 7	Semantic Error
Invalid overload of 'std::endl'	a.cpp	/a/src	line 13	Semantic Error
Field 'm' could not be resolved	a.cpp	/a/src	line 18	Semantic Error
Invalid overload of 'std::endl'	a.cpp	/a/src	line 18	Semantic Error


index.php/fa/41509/0/
index.php/fa/41510/0/

Is this a bug in Eclipse, or do I configure something incorrectly.
  • Attachment: Capture1.PNG
    (Size: 28.00KB, Downloaded 622 times)
  • Attachment: Capture2.PNG
    (Size: 25.59KB, Downloaded 638 times)
Re: CodeAnalyzer errors - c++17 - tuple and structured bindings [message #1854531 is a reply to message #1849027] Wed, 24 August 2022 06:33 Go to previous messageGo to next message
Mohith Manoj is currently offline Mohith ManojFriend
Messages: 2
Registered: October 2021
Junior Member
I am also facing the same issue. I have others in my team who faces the same issue while using structured binding.

The code for the screenshot attached compiles and runs perfectly.
index.php/fa/42436/0/

Eclipse version details.
Version: 2022-06 (4.24.0)
Build id: 20220609-1112


Codan version details
Provider : Eclipse CDT
Plug-in Name: Codan Analysis UI for C/C++
Version: 3.6.100.202204261256
Plug-in ID: org.eclipse.cdt.codan.ui.cxx
Re: CodeAnalyzer errors - c++17 - tuple and structured bindings [message #1854730 is a reply to message #1854531] Mon, 05 September 2022 03:27 Go to previous message
Kent Dorfman is currently offline Kent DorfmanFriend
Messages: 20
Registered: December 2020
Junior Member
I have similar issues under a non-managed project. Instead doing external Makefile build, so I have no option to set the C++ dialect in the project. I think that at the very least the code analyzer needs to have an option to specify the c++ standard being used, but cannot find any work-around.

I'm suspecting that the analyzer just cannot handle C++ 17 syntax yet...as was aluded to in a CDT whitepaper.
Previous Topic:gcc compiler and jtag device
Next Topic:Access Modifiers in C and C++
Goto Forum:
  


Current Time: Thu Apr 25 09:37:00 GMT 2024

Powered by FUDForum. Page generated in 0.02616 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top