Skip to content

Fix compilation error when using Kokkos's nvcc_wrapper - #1933

Open
ylee88 wants to merge 1 commit into
openPMD:devfrom
ylee88:kokkos-nvcc-workaround
Open

Fix compilation error when using Kokkos's nvcc_wrapper#1933
ylee88 wants to merge 1 commit into
openPMD:devfrom
ylee88:kokkos-nvcc-workaround

Conversation

@ylee88

@ylee88 ylee88 commented Aug 28, 2026

Copy link
Copy Markdown

Apparently, nvcc with -x cu option parses json::basic_json weirdly, and fails to compile. For example,

mwe.cxx:

template <class T = int>
struct basic_json {
    struct type_error {};
};

using json = basic_json<>;

void func()
{
    try {
    }
    catch (json::basic_json::type_error &) {
    }
}

The code above is a valid C++ and it compiles fine even with nvcc. However, it fails if I pass -x cu:

❯ nvcc -x cu mwe.cxx -c
mwe.cxx: In function ‘void func()’:
mwe.cxx:12:8: error: ‘json {aka basic_json<>}::basic_json’ names the constructor, not the type
   12 |     catch (json::basic_json::type_error &) {
      |        ^~~~
mwe.cxx:12:8: error: and ‘json’ {aka ‘basic_json<>’} has no template constructors
mwe.cxx:12:24: error: expected ‘)’ before ‘<’ token
   12 |     catch (json::basic_json::type_error &) {
      |       ~                ^
      |                        )
mwe.cxx:12:24: error: expected ‘{’ before ‘<’ token
mwe.cxx:12:24: error: expected primary-expression before ‘<’ token
mwe.cxx:12:25: error: expected primary-expression before ‘>’ token
   12 |     catch (json::basic_json::type_error &) {
      |                         ^
mwe.cxx:12:29: error: ‘::type_error’ has not been declared
   12 |     catch (json::basic_json::type_error &) {
      |                             ^~~~~~~~~~
mwe.cxx:12:41: error: expected primary-expression before ‘)’ token
   12 |     catch (json::basic_json::type_error &) {
      |                                         ^

This only matters when openPMD-api is compiled with nvcc_wrapper provided by Kokkos, whose passes -x cu to every source code.

This PR drops the redundant qualifier, as json is already an alias for basic_json<>, and make it compilable even with Kokkos's nvcc_wrapper.

@franzpoeschel franzpoeschel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

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

Successfully merging this pull request may close these issues.

2 participants