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

intellisense with std::map is broken #438

Closed
seisowl opened this issue Jun 29, 2023 · 17 comments · Fixed by #580
Closed

intellisense with std::map is broken #438

seisowl opened this issue Jun 29, 2023 · 17 comments · Fixed by #580
Labels
language C/C++ Language Support
Milestone

Comments

@seisowl
Copy link

seisowl commented Jun 29, 2023

Describe the bug
It looks like the intellisense does not recognize std::map. It used to work.

To Reproduce
Steps to reproduce the behavior:

  1. create a c++ project and #include <map> #include <utility>
  2. declarations with std::pair works with intellisense, while std::map had a red underline. Click on #include <map> goes to the correct header file.

Expected behavior
std::map should be recognized by the intellisense.

Screenshots
NA

Desktop (please complete the following information):

  • OS: Ubuntu 22.04.2 LTS
@jonahgraham
Copy link
Member

Hi @seisowl

Thanks for the bug report.

It used to work.

In the "used to work" did it stop working when you made an update, either to your C++ install or to your Eclipse CDT install? As libstdc++ evolves and takes on new features it can sometimes expose areas of the CDT parser that cause issue.

Can you confirm the following:

  • Version of Eclipse/CDT and where you obtained it from (e.g. 2023-06 downloaded from eclipse.org)
  • Version of g++ or if not using g++ what compiler and version you are using
  • If possible, when it was known to work

Finally, if you haven't changed versions, the problem may be a corrupted index. You can reindex and see if there is anything in the log. See the first paragraph of https://github.com/eclipse-cdt/cdt/blob/main/FAQ/Indexer.md#diagnosing-the-index for more info.

@jonahgraham jonahgraham added the language C/C++ Language Support label Jun 29, 2023
@i-garrison
Copy link
Contributor

Hi @seisowl please check with -std=c++11 or -std=c++14 as well.

There is at least a problem with ambiguous bindings for constructors which shows up more frequently with c++17 deduction guides. Also there is a problem with initializer list constructors where one of aggregate initialization cases is not handled in CDT parser. Ambiguous bindings from indexer do not look trivial to handle so I only have experimental fix for these in CDT parser which does not help in all cases. LSP integration should help here.

@cferr
Copy link

cferr commented Jun 30, 2023

I can confirm the bug is reproducible on my end (Eclipse version: 2023-06 (4.28.0), Build id: 20230608-1333, CDT Version: 11.2.0.202306051917, Build id: 20230605-1917).
The bug is absent in Eclipse 2023-03 (Version: 2023-03 (4.27.0), Build id: 20230309-1520, CDT Version: 11.1.0.202303061654, Build id: 20230306-1654).

To reproduce: take the following code

#include <map>
#include <string>

int main() {
	std::map<std::string, std::string> testMap;
	return 0;
}

CDT indexer reports "invalid template arguments" on the map<string, string> type if the standard is set to -std=c++17 or -std=c++2a, but succeeds if -std=c++14.

@i-garrison, the indexer log indeed reports an ambiguous node. The log is as follows:

!ENTRY org.eclipse.cdt.core 4 0 2023-06-30 08:07:11.138
!MESSAGE Error: Encountered an ambiguous node "std::uses_allocator_construction_args<_Tp2>(__a)" at /usr/include/c++/13.1.1/bits/uses_allocator_args.h, line 149 while parsing /tmp/test-workspace/test/src/test.cpp
!STACK 0
org.eclipse.cdt.internal.core.parser.ParserException: Encountered an ambiguous node "std::uses_allocator_construction_args<_Tp2>(__a)" at /usr/include/c++/13.1.1/bits/uses_allocator_args.h, line 149 while parsing /tmp/test-workspace/test/src/test.cpp
	at org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode.logAmbiguousNodeError(ASTAmbiguousNode.java:191)
	at org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode.getEvaluation(ASTAmbiguousNode.java:181)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression.computeEvaluation(CPPASTFunctionCallExpression.java:311)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression.getEvaluation(CPPASTFunctionCallExpression.java:295)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor$ReturnTypeDeducer.onReturnStatement(CPPVisitor.java:2642)
	at org.eclipse.cdt.core.dom.ast.util.ReturnStatementVisitor.visit(ReturnStatementVisitor.java:73)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement.accept(CPPASTReturnStatement.java:79)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement.accept(CPPASTCompoundStatement.java:103)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.deduceReturnType(CPPVisitor.java:2695)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createAutoFunctionType(CPPVisitor.java:2762)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createAutoType(CPPVisitor.java:2505)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createType(CPPVisitor.java:2322)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createType(CPPVisitor.java:2290)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveFunctionDeclaration(CPPSemantics.java:3314)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveFunction(CPPSemantics.java:3091)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveAmbiguities(CPPSemantics.java:2800)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveAmbiguities(CPPSemantics.java:2444)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.getBinding(CPPScope.java:133)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.getBinding(CPPScope.java:413)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createBinding(CPPVisitor.java:885)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createBinding(CPPVisitor.java:354)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName.createIntermediateBinding(CPPASTName.java:67)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase.resolvePreBinding(CPPASTNameBase.java:98)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.addCandidate(CPPScope.java:314)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.getBindingsInAST(CPPScope.java:278)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScope.getBindings(CPPScope.java:192)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.getBindingsFromScope(CPPSemantics.java:1787)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.lookup(CPPSemantics.java:1504)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics.resolveBinding(CPPSemantics.java:379)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createBinding(CPPVisitor.java:325)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPTemplates.createBinding(CPPTemplates.java:725)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateId.createIntermediateBinding(CPPASTTemplateId.java:126)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase.resolveBinding(CPPASTNameBase.java:111)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor.createBinding(CPPVisitor.java:343)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTName.createIntermediateBinding(CPPASTName.java:67)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase.resolvePreBinding(CPPASTNameBase.java:98)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateIDAmbiguity.checkNames(CPPASTTemplateIDAmbiguity.java:124)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateIDAmbiguity.doResolveAmbiguity(CPPASTTemplateIDAmbiguity.java:84)
	at org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode.resolveAmbiguity(ASTAmbiguousNode.java:87)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguityResolver.visit(CPPASTAmbiguityResolver.java:87)
	at org.eclipse.cdt.internal.core.dom.parser.ASTAmbiguousNode.accept(ASTAmbiguousNode.java:70)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionCallExpression.accept(CPPASTFunctionCallExpression.java:227)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTReturnStatement.accept(CPPASTReturnStatement.java:91)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTCompoundStatement.accept(CPPASTCompoundStatement.java:103)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition.accept(CPPASTFunctionDefinition.java:225)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTAmbiguityResolver.visit(CPPASTAmbiguityResolver.java:181)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition.accept(CPPASTFunctionDefinition.java:191)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration.accept(CPPASTTemplateDeclaration.java:131)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNamespaceDefinition.accept(CPPASTNamespaceDefinition.java:144)
	at org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit.accept(ASTTranslationUnit.java:289)
	at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTranslationUnit.resolveAmbiguities(CPPASTTranslationUnit.java:245)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.resolveAmbiguities(AbstractGNUSourceCodeParser.java:707)
	at org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parse(AbstractGNUSourceCodeParser.java:690)
	at org.eclipse.cdt.core.dom.parser.AbstractCLikeLanguage.getASTTranslationUnit(AbstractCLikeLanguage.java:171)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.createAST(AbstractIndexerTask.java:1244)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.parseFile(AbstractIndexerTask.java:1102)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.parseLinkage(AbstractIndexerTask.java:910)
	at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.runTask(AbstractIndexerTask.java:572)
	at org.eclipse.cdt.internal.core.pdom.indexer.PDOMIndexerTask.run(PDOMIndexerTask.java:164)
	at org.eclipse.cdt.internal.core.pdom.indexer.PDOMRebuildTask.run(PDOMRebuildTask.java:94)
	at org.eclipse.cdt.internal.core.pdom.PDOMIndexerJob.run(PDOMIndexerJob.java:160)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

@spamdaemon
Copy link

spamdaemon commented Jun 30, 2023

I've been running into this for a while now as well, ever since I accidentally upgraded my 2023-03. Switching to fresh install didn't work either.

#include <set>

static ::std::set<char> fails;
static ::std::set<char, ::std::less<char>> works;

I just tried with 2023-03 as well and that works just fine.

g++ (SUSE Linux) 13.1.1 20230522 [revision dd36656ada05731c069ecd5b1878380294fb1f3e]

@i-garrison
Copy link
Contributor

I've been running into this for a while now as well, ever since I accidentally upgraded my 2023-03. Switching to fresh install didn't work either.

Before support for deduction guides landed it did not fully worked anyway for >= c++17 so if you do not use that set --std=c++14 or earlier.

#include <set>

static ::std::set<char> fails;
static ::std::set<char, ::std::less<char>> works;

This is about the test case I'm using to reproduce the issue. Unfortunately the source of ambiguity is not clear to me yet: it looks like index lookup for default template argument returns extra hits (in this case, for ::std::less) and I cannot explain all of these extras yet.

I just tried with 2023-03 as well and that works just fine.

g++ (SUSE Linux) 13.1.1 20230522 [revision dd36656ada05731c069ecd5b1878380294fb1f3e]

This looks modern and suggests your GCC is already defaulting to c++17 or later which could explain why you see the issue.

@amurashkin17
Copy link

I have the same issue. Updated Eclipse today. Created new workspace with default settings. Created new project and test cpp file. Tried c++17 and c++2a dialects. Got "Invalid Template Arguments" error for std::map and std::unordered_map.

  • gcc (GCC) 13.1.1 20230511 (Red Hat 13.1.1-2)
  • Fedora release 38 (Thirty Eight)
  • Eclipse: 2023-06 (4.28.0) Build id 20230608-1333
  • Eclipse CDT: Ecliplse C/C++ Development Tools 11.2.0.202306051917
#include <map>
#include <unordered_map>

namespace {
	std::map<int,int> m1;
	std::unordered_map<int,int> m2;
}

In properties,

  • command to get compiler specs: ${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"
  • all options: -std=c++2a -O0 -g3 -Wall -c -fmessage-length=0 -Wno-attributes

Error log contains messages similar to the ones below

Error: Encountered an ambiguous node "std::uses_allocator_construction_args<_Tp2>(__a)" at /usr/include/c++/13/bits/uses_allocator_args.h, line 149 while parsing/Workspace/C++Test/Test5/test5.cpp
Error: Encountered an ambiguous node "std::uses_allocator_construction_args<_Tp2>(__a)" at /usr/include/c++/13/bits/uses_allocator_args.h, line 149 while parsing /home/mur/Workspace/C++Test/Test5/test5.cpp

c++14 works OK but, unfortunately, is not feasible.

@N3ar
Copy link

N3ar commented Sep 5, 2023

Just wondering if there is any movement on this, if it is marked for development, or if it would be best to get a version from before 2023-03?

@jonahgraham
Copy link
Member

The movement on this is the migration path being worked on to LSP support in CDT which will support all the latest C++ standards. That work is ongoing with the intention of a first released version in the coming weeks.

@sergeniously
Copy link

I've found a temporary workaround for this issue.
All you need is downgrade __cpp_deduction_guide definition fetched by the get compiler specs command.
Just write a script which will replace a line with original __cpp_deduction_guide definition.
For example, for Linux developers script could look like that:

#!/bin/bash
##
# This script is used to downgrade __cpp_deduction_guides definition
#     to avoid Eclipse indexer's inability to correctly work with it.
# See Project > Properties > C/C++ General > Preprocessor ... >
#     Providers > CDT GCC Built-in Compiler Settings.
##

"$@" | sed -e '/__cpp_deduction_guides/c #define __cpp_deduction_guides 201600L'

Locate this script somewhere inside of your project directory (for example, in ~/.settings/spec.sh).
And finally, specify it in a command to get compiler specs (Project > Properties > C/C++ General > Preprocessor ... > Providers > CDT GCC Built-in Compiler Settings) in following particular way:

${CWD}/.settings/spec.sh ${COMMAND} ${FLAGS} -E -P -v -dD -std=c++17 "${INPUTS}"

Don't forget to rebuild the index.

@gvl2023
Copy link

gvl2023 commented Oct 3, 2023

@sergeniously, you're my hero. From a quick test it looks like adding it under CDT User Setting Entries works as well - no need for the sed script, it doesn't seem that selecting "treat as built-in" makes a difference.

image

@i-garrison
Copy link
Contributor

i-garrison commented Oct 5, 2023

Minimal reproducer at the moment:

header file: testcxx17-unordered-map-resolution-bug-minimal.h
#pragma once

namespace test
{
typedef long unsigned int size_t;
template<typename _Tp = void> struct Dependent;
}

template<typename _Key, typename _Equal> struct Intermediate
{
public:
    typedef test::size_t size_type;
};

template<typename _Key, typename _Dependent = test::Dependent<_Key>>
class Base {
    typedef Intermediate<_Key, _Dependent> _Intermediate;

public:
    typedef typename _Intermediate::size_type size_type;
};
source file: testcxx17-unordered-map-resolution-bug-minimal.cc
#include "testcxx17-unordered-map-resolution-bug-minimal.h"

using test_base_size_type = Base<int>::size_type;

namespace test_std_alternative {
template<typename A, typename B>
class Unrelated;

  using namespace test;
  template<typename _Key>
  Unrelated(_Key)
    -> Unrelated<_Key, Dependent <_Key>>;
}

Steps to reproduce:

  1. Load both files, make sure indexer is enabled and compiler C++ standard is at least 17 so __cpp_deduction_guides macro is 201703L or better.
  2. Modify header file and save it to trigger indexer.
  3. see Base<int>::size_type errors out like this Type 'Base<int>::size_type' could not be resolved

Strange thing is that you have to modify the header file to reproduce. Another thing is this works if you move everything to header file. It appears that deduction guide detection code is somehow causing this issue, probably somewhere in PDOM interactions but nothing concrete to point out yet.

i-garrison added a commit to i-garrison/cdt that referenced this issue Oct 7, 2023
Add new index binding resolution test strategy SinglePDOMReindexedTestStrategy
which does reindex project after adding test case sources. Clean up redundand
C++17 setup helper classes from test since deduction guides are always enabled.

Add test case modelling std::map resolution problem and make sure to run it with
new test strategy to reproduce the issue.

Bug eclipse-cdt#438
i-garrison added a commit to i-garrison/cdt that referenced this issue Oct 7, 2023
Turned out that index is missing information about template parameters of
deduction guide templates, and all affected names which are only available
via index could not be resolved. This happens to e.g. std::map<> which is
usually looked up via index populated from <map> header file.

Fix this by implementing ICPPTemplateParameterOwner and ICPPTemplateDefinition
interfaces in new CPPDeductionGuideTemplate which delegates missing resolution
calls to the function object which already carry required template information.

Closes eclipse-cdt#438
@i-garrison
Copy link
Contributor

#580 should fix this issue

i-garrison added a commit to i-garrison/cdt that referenced this issue Oct 10, 2023
Add new index binding resolution test strategy SinglePDOMReindexedTestStrategy
which does reindex project after adding test case sources. Clean up redundand
C++17 setup helper classes from test since deduction guides are always enabled.

Add test case modelling std::map resolution problem and make sure to run it with
new test strategy to reproduce the issue.

Bug eclipse-cdt#438
i-garrison added a commit to i-garrison/cdt that referenced this issue Oct 10, 2023
Turned out that index is missing information about template parameters of
deduction guide templates, and all affected names which are only available
via index could not be resolved. This happens to e.g. std::map<> which is
usually looked up via index populated from <map> header file.

Fix this by implementing ICPPTemplateParameterOwner and ICPPTemplateDefinition
interfaces in new CPPDeductionGuideTemplate which delegates missing resolution
calls to the function object which already carry required template information.

Closes eclipse-cdt#438
jonahgraham pushed a commit to i-garrison/cdt that referenced this issue Dec 28, 2023
Add new index binding resolution test strategy SinglePDOMReindexedTestStrategy
which does reindex project after adding test case sources. Clean up redundand
C++17 setup helper classes from test since deduction guides are always enabled.

Add test case modelling std::map resolution problem and make sure to run it with
new test strategy to reproduce the issue.

Bug eclipse-cdt#438
jonahgraham pushed a commit to i-garrison/cdt that referenced this issue Dec 28, 2023
Turned out that index is missing information about template parameters of
deduction guide templates, and all affected names which are only available
via index could not be resolved. This happens to e.g. std::map<> which is
usually looked up via index populated from <map> header file.

Fix this by implementing ICPPTemplateParameterOwner and ICPPTemplateDefinition
interfaces in new CPPDeductionGuideTemplate which delegates missing resolution
calls to the function object which already carry required template information.

Closes eclipse-cdt#438
jonahgraham pushed a commit that referenced this issue Dec 28, 2023
Add new index binding resolution test strategy SinglePDOMReindexedTestStrategy
which does reindex project after adding test case sources. Clean up redundand
C++17 setup helper classes from test since deduction guides are always enabled.

Add test case modelling std::map resolution problem and make sure to run it with
new test strategy to reproduce the issue.

Bug #438
jonahgraham pushed a commit that referenced this issue Dec 28, 2023
Turned out that index is missing information about template parameters of
deduction guide templates, and all affected names which are only available
via index could not be resolved. This happens to e.g. std::map<> which is
usually looked up via index populated from <map> header file.

Fix this by implementing ICPPTemplateParameterOwner and ICPPTemplateDefinition
interfaces in new CPPDeductionGuideTemplate which delegates missing resolution
calls to the function object which already carry required template information.

Closes #438
@SubBastion
Copy link

still occurs with both #inlcude <map> and #include <unordered_map>

@i-garrison
Copy link
Contributor

still occurs with both #inlcude <map> and #include <unordered_map>

Please open new issue and provide more details, e.g. which cdt version and c++ compiler this is still seen with and what was the source code (preferrably extract a small test case from it.) Note you probably cannot expect all cases to work with C++20 and above due to missing support for concepts and constraints, but with C++17 it should work already pretty well.

@i-garrison
Copy link
Contributor

@jonahgraham would you believe marking this issue with milestone (e.g. to see this should be fixed in upcoming 11.x release) would help navigating through issues?

@gvl2023
Copy link

gvl2023 commented Feb 22, 2024

still occurs with both #inlcude <map> and #include <unordered_map>

The fix didn’t make it to 11.4/2023.12 if that’s what you’re using.

@jonahgraham jonahgraham added this to the 11.5.0 milestone Feb 22, 2024
@jonahgraham
Copy link
Member

@jonahgraham would you believe marking this issue with milestone (e.g. to see this should be fixed in upcoming 11.x release) would help navigating through issues?

Yes - I have focused on PRs in the past, but the issues having the milestones too is a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language C/C++ Language Support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants