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

Using constexpr in c/c++ codes throws a IllegalStateException error #994

Open
Bhargavi136 opened this issue Jan 7, 2025 · 0 comments
Open

Comments

@Bhargavi136
Copy link

Describe the bug
In Eclipse CDT, C/C++ editor fails to find a symbol with "Open Declaration F12" sub menu.
Even if symbol is in the same file. (modified the default F3 binding to F12).

Preferences/C/C++ indexer is configured as follow :
Enable indexer
Index all header variants
Index source and header files opened in editor
Allow heuristic resolution of includes
Skip files larger than 8MB
Skip includes files larger than 16MB
Automatically update the index
Use active Build configuration
Cache limits heap 20%, absolute limit 512MB (Doubling cache limit from 256 to 512MB had no effect.)

Indexer stops sometimes with this trace in the Error Log.
Too many errors while indexing, stopping indexer.
An exception stack trace is not available.
This issue is populating in both Windows and Linux operating system

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'----go to new -> click on c/c++ project
  2. Click on '....'-----Create a small code snippet using constexpr save it. Before building it will through error in error log whenever the indexer is started.
  3. Scroll down to '....'-----open the error log (windows-> show view -> Error log)
  4. See error-- "Error while parsing /test/src/const.cpp.
    java.lang.IllegalStateException: Trying to set incomplete value
    at org.eclipse.cdt.internal.core.dom.parser.IntegralValue.setSubValue(IntegralValue.java:286)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalCompositeAccess.update(EvalCompositeAccess.java:53)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalBinary.computeForFunctionCall(EvalBinary.java:503)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecExpressionStatement.executeForFunctionCall(ExecExpressionStatement.java:39)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUtil.executeStatement(EvalUtil.java:87)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecCompoundStatement.executeForFunctionCall(ExecCompoundStatement.java:63)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUtil.executeStatement(EvalUtil.java:94)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecFor.executeForFunctionCall(ExecFor.java:45)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalUtil.executeStatement(EvalUtil.java:94)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExecCompoundStatement.executeForFunctionCall(ExecCompoundStatement.java:63)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionCall.evaluateFunctionBody(EvalFunctionCall.java:350)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.EvalFunctionCall.getValue(EvalFunctionCall.java:187)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable.computeInitialValue(CPPVariable.java:271)
    at org.eclipse.cdt.internal.core.dom.parser.cpp.CPPVariable.getInitialValue(CPPVariable.java:248)
    at org.eclipse.cdt.internal.core.pdom.PDOMWriter.resolveNames(PDOMWriter.java:441)
    at org.eclipse.cdt.internal.core.pdom.PDOMWriter.addSymbols(PDOMWriter.java:284)
    at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.writeToIndex(AbstractIndexerTask.java:1295)
    at org.eclipse.cdt.internal.core.pdom.AbstractIndexerTask.parseFile(AbstractIndexerTask.java:1107)
    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:96)
    at org.eclipse.cdt.internal.core.pdom.PDOMIndexerJob.run(PDOMIndexerJob.java:160)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Expected behavior
C++20 supports the constexpr containers std::vector and std::string. constexpr means, in this case, that the member functions of both containers can be applied at compile-time.

In my following example, I use instead of a constexpr std::vector a constexpr std::array. Since C++17 std::array can be declared as constexpr: constexpr std::array myArray{}.

With C++20, we can use a std::array at compile-time.

#include
#include

using namespace std;

enum

{ ENUM_COM_ACQ,
ENUM_COM_LAST_ACQ = (ENUM_COM_ACQ + 128 -1),
ENUM_COM_SYNCDET_PROD,
ENUM_COM_TRT_UNIT,
ENUM_COM_SYNCDET_BROU ,
ENUM_COM_GENERALE,
ENUM_COM_IMAGES_PC ,
ENUM_NB_CANAUX_COM,
ENUM_CANAUX_COM};
/// Static initialisation of msg_par_canal; compile time.
constexpr static std::array<unsigned int, ENUM_NB_CANAUX_COM> MakeMsgPerChannel()
{
std::array<unsigned int, ENUM_NB_CANAUX_COM> arr{};

for (unsigned int iChannel = 0; iChannel <= ENUM_COM_LAST_ACQ; iChannel++)

{
arr[iChannel] = 10;
}

arr[ENUM_COM_SYNCDET_PROD] = 200;
arr[ENUM_COM_TRT_UNIT] = 40;
arr[ENUM_COM_SYNCDET_BROU] = 200;
arr[ENUM_COM_GENERALE] = 100;
arr[ENUM_COM_IMAGES_PC] = 10;
return arr;
}

class MessageQueueManager

{ public: MessageQueueManager(); virtual ~MessageQueueManager() = default;
static constexpr std::array<unsigned int, ENUM_NB_CANAUX_COM> msg_par_canal = MakeMsgPerChannel(); }
;

int main() {
cout << "!!!HELLO!!!" << endl;
return 0;
}

Getting the Output as excepted but I am getting error in error log as decribed above. Expecting the error free log while indexer starts to build.
Error is populating in error log whenever we try to rebuild (project -> c/c++ index -> rebuild).

Screenshots
Attached.
screenshot_with_error
fix_for_index_constexpr

working_fine_with_Indexer.mp4

Version Information (please complete the following information):
OS build: 22631.4602 and OS Version: 23H2 Edition: Windows 11 pro
Eclipse SDK Version: 2022-06 (4.24)
CDT Version: 11.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant