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

Error compiling with -std=c++20 using CUDA/Clang #2627

Closed
andrewcorrigan opened this issue Dec 3, 2021 · 2 comments · Fixed by #2630
Closed

Error compiling with -std=c++20 using CUDA/Clang #2627

andrewcorrigan opened this issue Dec 3, 2021 · 2 comments · Fixed by #2630

Comments

@andrewcorrigan
Copy link
Contributor

andrewcorrigan commented Dec 3, 2021

I'm encountering errors compiling with clang++ -x cuda using -std=c++20. I observed this on the current commit on master and bisected to the commit where the errors arose to be [fd34a3d].

A simple reproducer is:

#include <iostream>
#include <fmt/ostream.h>

int main(int argc, char** argv)
{
    std::cout << fmt::format("hello {}", "world") << std::endl;

    return 0;
}

The errors are triggered using Clang 10, 11, 12 (perhaps 13 as well, but I can't test that immediately) with the following command-line arguments:

% clang++ -x cuda -std=c++20 -c --cuda-gpu-arch=sm_35 -Ifmt/include test_fmt.cpp

The first of ten error messages is:

fmt/include/fmt/core.h:957:27: error: non-virtual member function marked 'override' hides virtual member function
  void grow(size_t) final FMT_OVERRIDE {
                          ^
fmt/include/fmt/core.h:129:26: note: expanded from macro 'FMT_OVERRIDE'
#    define FMT_OVERRIDE override
                         ^
fmt/include/fmt/core.h:3002:14: note: in instantiation of template class 'fmt::v8::detail::counting_buffer<char>' requested here
  auto buf = detail::counting_buffer<>();
             ^
fmt/include/fmt/core.h:798:32: note: hidden overloaded virtual function 'fmt::v8::detail::buffer<char>::grow' declared here
  virtual FMT_CONSTEXPR20 void grow(size_t capacity) = 0;
                               ^

Note, the following builds fine:

  1. CUDA in C++17 mode:
% clang++ -x cuda -std=c++17 -c --cuda-gpu-arch=sm_35 -Ifmt/include test_fmt.cpp
  1. C++20 mode without CUDA:
% clang++ -std=c++20 -c -Ifmt/include test_fmt.cpp
@andrewcorrigan
Copy link
Contributor Author

It looks like Clang/CUDA wants constexpr to be consistent between the base class and the override.

There are two ways to fix the errors:

  1. Decorate all overrides of grow with FMT_CONSTEXPR20, or,
  2. Eliminate FMT_CONSTEXPR20 from the abstract declaration of grow in class buffer.

I'd be happy to prepare a PR pending feedback on which approach would be preferred.

andrewcorrigan added a commit to andrewcorrigan/fmt that referenced this issue Dec 3, 2021
@vitaut
Copy link
Contributor

vitaut commented Dec 3, 2021

I think we should go with option 1 because option 2 would break compile-time formatting. A PR is welcome.

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 a pull request may close this issue.

2 participants