This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 31st, when you will be able to use this site as normal.

    Forum Stats

  • 3,890,592 Users
  • 2,269,776 Discussions
  • 7,916,825 Comments

Discussions

Undefined symbol using static constexpr

Jacob Barrett
Jacob Barrett Member Posts: 3

The following code using static constexp on a class results in and undefined symbol the on the 12.5 linker but links fine in GCC, Clang and Visual C++.

test.h:

class Test { public:  static constexpr auto CONST_VALUE = "const value";  static constexpr auto CONST_OTHER = "const other";};

test.cpp:

#include <iostream>#include "test.h"int main() { std::cout << Test::CONST_VALUE;}

When compiled:

$ CC -std=c++11 test.cpp -o testUndefined                       first referenced symbol                             in fileTest::CONST_VALUE              test.o[Hint: static member Test::CONST_VALUE must be defined in the program]

Notice no compiler error is given when processing the header and that only for the variable being accessed in the cpp file gives an error at link time.

-Jake

Jacob Barrett

Best Answer

  • Steve.Clamage-Oracle
    Steve.Clamage-Oracle Oracle Studio C++ Project Lead Santa Clara, CA, USAMember Posts: 775
    edited Jun 13, 2017 10:07AM Answer ✓

    Thanks for reporting this bug. It did not show up in our testing.  I have filed bug 26266705 for the problem.

    As a workaround, you can add a definition outside the class of the static data member. Unfortunately, you can't use "auto" in the definition because you can't repeat the initializer.

    constexpr const char* Test::CONST_VALUE ;

    It is now too late to fix this bug for the Studio 12.6 release. If you have a service contract for Studio, please go through your support channel and say that you want to escalate this bug for a fix in a patch.

    Jacob Barrett

Answers

  • Steve.Clamage-Oracle
    Steve.Clamage-Oracle Oracle Studio C++ Project Lead Santa Clara, CA, USAMember Posts: 775
    edited Jun 13, 2017 10:07AM Answer ✓

    Thanks for reporting this bug. It did not show up in our testing.  I have filed bug 26266705 for the problem.

    As a workaround, you can add a definition outside the class of the static data member. Unfortunately, you can't use "auto" in the definition because you can't repeat the initializer.

    constexpr const char* Test::CONST_VALUE ;

    It is now too late to fix this bug for the Studio 12.6 release. If you have a service contract for Studio, please go through your support channel and say that you want to escalate this bug for a fix in a patch.

    Jacob Barrett
  • Steve.Clamage-Oracle
    Steve.Clamage-Oracle Oracle Studio C++ Project Lead Santa Clara, CA, USAMember Posts: 775
    edited Jun 13, 2017 11:35AM

    BTW, the problem is not generic. If Test::CONST_VALUE has, for example, a numeric type, the code works. Array types and pointer types exhibit this bug.

  • Jacob Barrett
    Jacob Barrett Member Posts: 3
    edited Jun 14, 2017 6:46PM

    Thanks!

    The suggested workaround compiles on all the other compilers as well so we are good for now.

    If you can say, will it be corrected in the followup release to 12.6 (12.7 or whatever)?

  • Steve.Clamage-Oracle
    Steve.Clamage-Oracle Oracle Studio C++ Project Lead Santa Clara, CA, USAMember Posts: 775
    edited Jun 16, 2017 9:50AM

    Many external and internal factors affect the priority of a bug fix. Unless a bug is escalated, it is generally impossible to say when a fix will become available.

This discussion has been closed.