Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*

cannot assign to non-static data member

Caius
Beginner
458 Views

Hello:

  When I use the oneAPI2025.0 compiler to compile SPEC2006 483.xalancbmk, I encounter the following error :


./xercesc/util/NameIdPool.c:416:20: error: cannot assign to non-static data member 'fMemoryManager' with const-qualified type 'MemoryManager *const'
416 | fMemoryManager = toAssign.fMemoryManager;
| ~~~~~~~~~~~~~~ ^
./xercesc/util/NameIdPool.hpp:332:29: note: non-static data member 'fMemoryManager' declared const here
332 | MemoryManager* const fMemoryManager;
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
1 error generated.
specmake: *** [WFXMLScanner.o] Error 1

 

 

what shouold i do with this error?

0 Kudos
4 Replies
Caius
Beginner
420 Views

I can not change the source code of SPEC2006, and it is not allowed.

The same compilation options can be successfully compiled in the OneAPI2023.2.0 version, but this issue occurred after upgrading to the 2025 version

0 Kudos
Caius
Beginner
421 Views

I can not change the source code of SPEC2006, and it is not allowed.

The same compilation options can be successfully compiled in the OneAPI2023.2.0 version, but this issue occurred after upgrading to the 2025 version

0 Kudos
dusktilldawn
New Contributor I
360 Views

The error you're encountering happens because the code is trying to modify a const-qualified data member (fMemoryManager), which is not allowed in C++.

 

In your case, the data member fMemoryManager is declared as MemoryManager* const fMemoryManager; in the header file NameIdPool.hpp, meaning that it is a constant pointer (i.e., the pointer itself cannot be changed after initialization, but the object it points to can be).

 

However, in the code NameIdPool.c (at line 416), there's an attempt to assign a new value to fMemoryManager, which is illegal because fMemoryManager is declared const.

 

HOW TO RESOLVE THIS:


Check for const correctness:

The first thing you need to do is understand whether the pointer should truly be const. If fMemoryManager should not be modified after initialization, then the code trying to modify it is incorrect.


In that case, you'll need to refactor the code where fMemoryManager is assigned, ensuring that it doesn't try to change the pointer itself.


Remove const qualifier if appropriate:

If fMemoryManager should be mutable (i.e., you need to assign a new value to it later in the code), you can remove the const qualifier from its declaration. To do that, modify the declaration in NameIdPool.hpp:

// Change this line:
MemoryManager* const fMemoryManager;
// To this:
MemoryManager* fMemoryManager;


This will allow fMemoryManager to be reassigned, but it still allows modifying the object it points to.


Look for a deeper issue:

The issue may also be an indicator that the code was not originally intended to modify fMemoryManager in this way.

 

If this is part of a larger library or framework (like xercesc, which is used for XML processing), you may want to check the documentation or changelog for any updates that might address this problem.


Compiler/oneAPI version issue:

There could also be a compatibility issue with the oneAPI 2025 compiler you're using. It's possible that the error is related to how the compiler handles const-qualified members. In that case, trying to compile with a different compiler version (or checking for updates/patches for the oneAPI compiler) might help.

0 Kudos
AlHill
Super User
355 Views

@dusktilldawn   Are all of your posts going to be chatgpt answers?

 

Doc (not an Intel employee or contractor)
[Fear and the desire for control are primary motivators for shadow dwellers. ]

0 Kudos
Reply