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

Clang-8.0 (C++ 17 standard) compile StrFormat failed #271

Closed
fcharlie opened this issue Mar 6, 2019 · 6 comments
Closed

Clang-8.0 (C++ 17 standard) compile StrFormat failed #271

fcharlie opened this issue Mar 6, 2019 · 6 comments
Assignees

Comments

@fcharlie
Copy link

fcharlie commented Mar 6, 2019

When I build some program which depend with absl str_format use Clang-8.0 (C++ 17 standard ). The compiler report:

'FormatSpecTemplate' is unavailable: Format std::string is not
constexpr.

OS:

# lsb_release
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic

Linux Kernel:

#uname -a
Linux somehost 4.18.0-15-generic #16~18.04.1-Ubuntu SMP Thu Feb 7 14:06:04 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Clang Is 8.0 RC3, Version Details:

#clang -v
clang version 8.0.0 (clangbuilder 355381)
Target: x86_64-clangbuilder-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm-8.0/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Candidate multilib: .;@m64
Selected multilib: .;@m64

Code:

#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include <iostream>
#include <string>

int main(int argc, const char **argv) {
  for (int i = 0; i < argc; ++i) {
    std::string s = argv[i];
    std::cout << "--- >" << absl::StrFormat("Arg %d is %s\n", i, s);
    std::cout << absl::StrCat("Arg ", i, ": ", argv[i], "\n");
  }
}

cmake

# Required as the first line
cmake_minimum_required(VERSION 3.12)

# Define the crrent project
project(main VERSION 0.1)

# Tell Abseil which C++ standard to use
set(CMAKE_CXX_STANDARD 17)

# Process abseil with CMake
add_subdirectory(abseil-cpp)

# Define the target executable and its dependency on Abseil
add_executable(main main.cc)
target_link_libraries(main
  absl::str_format
  absl::strings
)

Output:

/tmp/abseil-hello/cmake-hello/main.cc:9:45: error: 'FormatSpecTemplate' is unavailable: Format std::string is not
      constexpr.
    std::cout << "--- >" << absl::StrFormat("Arg %d is %s\n", i, s);
                                            ^
/tmp/abseil-hello/cmake-hello/abseil-cpp/absl/strings/internal/str_format/bind.h:82:3: note: 'FormatSpecTemplate' has
      been explicitly marked unavailable here
  FormatSpecTemplate(...)  // NOLINT
  ^
1 error generated.
CMakeFiles/main.dir/build.make:62: recipe for target 'CMakeFiles/main.dir/main.cc.o' failed
make[2]: *** [CMakeFiles/main.dir/main.cc.o] Error 1
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

@EricWF
Copy link
Contributor

EricWF commented Mar 6, 2019

Thanks for the report. This appears to be a regression in the upcoming Clang release. We may have caught it in time to fix.

Here's a reproducer on godbolt: https://godbolt.org/z/k5RlV9

I'll do more investigation in the morning.

@fcharlie
Copy link
Author

fcharlie commented Mar 6, 2019

Thanks for the report. This appears to be a regression in the upcoming Clang release. We may have caught it in time to fix.

Here's a reproducer on godbolt: https://godbolt.org/z/k5RlV9

I'll do more investigation in the morning.

Then this problem should be independent of Absl, GCC-8.0 Clang-7.0 C++17/C++14 did not find this error.

@EricWF
Copy link
Contributor

EricWF commented Mar 6, 2019

Here's the fully reduced bug: https://godbolt.org/z/ksAjmq
Here's the Clang fix: https://reviews.llvm.org/D59038

I'll close this once I know if the fix will make it into Clang 8.

@fcharlie
Copy link
Author

fcharlie commented Mar 7, 2019

@EricWF Thanks.

@fcharlie
Copy link
Author

Rebuild clang and use it. This issue has been fixed. Thanks @EricWF

clang version 8.0.0 (clangbuilder 356006)
Target: x86_64-clangbuilder-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm-8.0/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Candidate multilib: .;@m64
Selected multilib: .;@m64

@EricWF
Copy link
Contributor

EricWF commented Mar 14, 2019

Thanks for confirming the fix.

I can confirm the fix will be a part of Clang 8.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

3 participants
@EricWF @fcharlie and others