llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.58k stars 11.81k forks source link

Error when including boost headers [clang-diagnostic-missing-template-arg-list-after-template-kw] #101079

Closed FoxLightning closed 2 months ago

FoxLightning commented 2 months ago

boost/qvm/quat_traits.hpp:82:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw] 82 | quat_traits::template write_element_idx(i, q) = s; (I don't include this header)

appear if use in cmake project with boost built from source v1.85 tried c++ standard 17 20 23 - same result

LLVM version 20.0.0git Optimized build. (on 18 was crash)

latest Mac OS cpu m1pro

file(GLOB_RECURSE CPP_FILES *.cpp)
include_directories(${PROJECT_SOURCE_DIR}/src/include)
add_executable(${PROJECT_NAME} ${CPP_FILES})

if (WIN32)
    target_link_libraries(
        ${PROJECT_NAME} PRIVATE SDL3main
    )
endif()

# third party libs
target_link_libraries(${PROJECT_NAME} PRIVATE
    SDL3::SDL3
    SDL3_image::SDL3_image
    SDL3_ttf::SDL3_ttf
    Boost::geometry
)
# clang-tidy setup
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
if(CLANG_TIDY_EXE)
    set(CLANG_TIDY_CONFIG_FILE ${PROJECT_SOURCE_DIR}/.clang-tidy)
    set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-config-file=${CLANG_TIDY_CONFIG_FILE}")
    message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
    message(STATUS "Using clang-tidy configuration: ${CLANG_TIDY_CONFIG_FILE}")
else()
    message(WARNING "clang-tidy not found!")
endif()
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}")
cmake_minimum_required(VERSION 3.16)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
# clang-tidy crashes on C++20 during linting boost/geometry headers
# even if headers dont include in HeaderFilterRegex
set(CMAKE_CXX_STANDARD 17)

project(GameOne VERSION 0.1)

# Black magic from one internet guy, need for run SDL3_image 
# (Probably usefull only for MacOS)
enable_language(OBJC)

add_subdirectory(lib/SDL)
add_subdirectory(lib/SDL_image)
add_subdirectory(lib/SDL_ttf)
add_subdirectory(lib/boost)
add_subdirectory(src)
image
/Users/bohdanlysychenko/GameOne/lib/boost/libs/qvm/include/boost/qvm/quat_traits.hpp:82:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw]
   82 |     quat_traits<Q>::template write_element_idx(i, q) = s;
      |                              ^
/Users/bohdanlysychenko/GameOne/lib/boost/libs/qvm/include/boost/qvm/quat_traits.hpp:92:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw]
   92 |     quat_traits<Q>::template write_element_idx(i, q, s);
      |                              ^
4 warnings and 2 errors generated.
Error while processing /Users/bohdanlysychenko/GameOne/src/cpp/GameBase/BaseController.cpp.
Suppressed 4 warnings (4 with check filters).
Found compiler error(s).
make[2]: *** [src/CMakeFiles/GameOne.dir/cpp/GameBase/BaseController.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/GameOne.dir/all] Error 2
make: *** [all] Error 2
keinflue commented 2 months ago

Clang is correctly rejecting the boost code. The template keyword must be followed by a template-id (i.e. a name followed by template argument list), except when the name refers to a class or alias template (and this use is deprecated).

From a quick look at the code, the template keyword simply should be removed.

I would suggest reporting the issue to boost/qvm.

See also https://github.com/llvm/llvm-project/issues/94194.

FoxLightning commented 2 months ago

Clang is correctly rejecting the boost code. The template keyword must be followed by a template-id (i.e. a name followed by template argument list), except when the name refers to a class or alias template (and this use is deprecated).

From a quick look at the code, the template keyword simply should be removed.

I would suggest reporting the issue to boost/qvm.

See also #94194.

If this is a normal situation, then why does clang compiler not produce this error? Why params -clang-diagnostic-missing-template-arg-list-after-template-kw and -Wno-missing-template-arg-list-after-template-kw in .clang-tidy dont work?

AaronBallman commented 2 months ago

Perhaps you've configured clang-tidy incorrectly?

https://godbolt.org/z/vv5GY7qY4

llvmbot commented 2 months ago

@llvm/issue-subscribers-c-1

Author: Bogdan (FoxLightning)

boost/qvm/quat_traits.hpp:82:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw] 82 | quat_traits<Q>::template write_element_idx(i, q) = s; (I don't include this header) appear if use in cmake project with boost built from source v1.85 tried c++ standard 17 20 23 - same result LLVM version 20.0.0git Optimized build. (on 18 was crash) latest Mac OS cpu m1pro ``` CMake file(GLOB_RECURSE CPP_FILES *.cpp) include_directories(${PROJECT_SOURCE_DIR}/src/include) add_executable(${PROJECT_NAME} ${CPP_FILES}) if (WIN32) target_link_libraries( ${PROJECT_NAME} PRIVATE SDL3main ) endif() # third party libs target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image SDL3_ttf::SDL3_ttf Boost::geometry ) # clang-tidy setup find_program(CLANG_TIDY_EXE NAMES "clang-tidy") if(CLANG_TIDY_EXE) set(CLANG_TIDY_CONFIG_FILE ${PROJECT_SOURCE_DIR}/.clang-tidy) set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-config-file=${CLANG_TIDY_CONFIG_FILE}") message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") message(STATUS "Using clang-tidy configuration: ${CLANG_TIDY_CONFIG_FILE}") else() message(WARNING "clang-tidy not found!") endif() set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}") ``` ``` CMake outer cmake_minimum_required(VERSION 3.16) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) # clang-tidy crashes on C++20 during linting boost/geometry headers # even if headers dont include in HeaderFilterRegex set(CMAKE_CXX_STANDARD 17) project(GameOne VERSION 0.1) # Black magic from one internet guy, need for run SDL3_image # (Probably usefull only for MacOS) enable_language(OBJC) add_subdirectory(lib/SDL) add_subdirectory(lib/SDL_image) add_subdirectory(lib/SDL_ttf) add_subdirectory(lib/boost) add_subdirectory(src) ``` <img width="461" alt="image" src="https://github.com/user-attachments/assets/c409be76-f5bb-477b-9fc1-fee7b421a7c0"> ``` Bash out /Users/bohdanlysychenko/GameOne/lib/boost/libs/qvm/include/boost/qvm/quat_traits.hpp:82:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw] 82 | quat_traits<Q>::template write_element_idx(i, q) = s; | ^ /Users/bohdanlysychenko/GameOne/lib/boost/libs/qvm/include/boost/qvm/quat_traits.hpp:92:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw] 92 | quat_traits<Q>::template write_element_idx(i, q, s); | ^ 4 warnings and 2 errors generated. Error while processing /Users/bohdanlysychenko/GameOne/src/cpp/GameBase/BaseController.cpp. Suppressed 4 warnings (4 with check filters). Found compiler error(s). make[2]: *** [src/CMakeFiles/GameOne.dir/cpp/GameBase/BaseController.cpp.o] Error 1 make[1]: *** [src/CMakeFiles/GameOne.dir/all] Error 2 make: *** [all] Error 2 ```
llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-tidy

Author: Bogdan (FoxLightning)

boost/qvm/quat_traits.hpp:82:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw] 82 | quat_traits<Q>::template write_element_idx(i, q) = s; (I don't include this header) appear if use in cmake project with boost built from source v1.85 tried c++ standard 17 20 23 - same result LLVM version 20.0.0git Optimized build. (on 18 was crash) latest Mac OS cpu m1pro ``` CMake file(GLOB_RECURSE CPP_FILES *.cpp) include_directories(${PROJECT_SOURCE_DIR}/src/include) add_executable(${PROJECT_NAME} ${CPP_FILES}) if (WIN32) target_link_libraries( ${PROJECT_NAME} PRIVATE SDL3main ) endif() # third party libs target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3 SDL3_image::SDL3_image SDL3_ttf::SDL3_ttf Boost::geometry ) # clang-tidy setup find_program(CLANG_TIDY_EXE NAMES "clang-tidy") if(CLANG_TIDY_EXE) set(CLANG_TIDY_CONFIG_FILE ${PROJECT_SOURCE_DIR}/.clang-tidy) set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};-config-file=${CLANG_TIDY_CONFIG_FILE}") message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}") message(STATUS "Using clang-tidy configuration: ${CLANG_TIDY_CONFIG_FILE}") else() message(WARNING "clang-tidy not found!") endif() set_target_properties(${PROJECT_NAME} PROPERTIES CXX_CLANG_TIDY "${CMAKE_CXX_CLANG_TIDY}") ``` ``` CMake outer cmake_minimum_required(VERSION 3.16) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) # clang-tidy crashes on C++20 during linting boost/geometry headers # even if headers dont include in HeaderFilterRegex set(CMAKE_CXX_STANDARD 17) project(GameOne VERSION 0.1) # Black magic from one internet guy, need for run SDL3_image # (Probably usefull only for MacOS) enable_language(OBJC) add_subdirectory(lib/SDL) add_subdirectory(lib/SDL_image) add_subdirectory(lib/SDL_ttf) add_subdirectory(lib/boost) add_subdirectory(src) ``` <img width="461" alt="image" src="https://github.com/user-attachments/assets/c409be76-f5bb-477b-9fc1-fee7b421a7c0"> ``` Bash out /Users/bohdanlysychenko/GameOne/lib/boost/libs/qvm/include/boost/qvm/quat_traits.hpp:82:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw] 82 | quat_traits<Q>::template write_element_idx(i, q) = s; | ^ /Users/bohdanlysychenko/GameOne/lib/boost/libs/qvm/include/boost/qvm/quat_traits.hpp:92:30: error: a template argument list is expected after a name prefixed by the template keyword [clang-diagnostic-missing-template-arg-list-after-template-kw] 92 | quat_traits<Q>::template write_element_idx(i, q, s); | ^ 4 warnings and 2 errors generated. Error while processing /Users/bohdanlysychenko/GameOne/src/cpp/GameBase/BaseController.cpp. Suppressed 4 warnings (4 with check filters). Found compiler error(s). make[2]: *** [src/CMakeFiles/GameOne.dir/cpp/GameBase/BaseController.cpp.o] Error 1 make[1]: *** [src/CMakeFiles/GameOne.dir/all] Error 2 make: *** [all] Error 2 ```
FoxLightning commented 2 months ago

Yes, indeed the problem was in the wrong arguments for the linter. I missed --extra-arg-before This helps me

--extra-arg-before=-Wno-missing-template-arg-list-after-template-kw

Thanks everyone for your help