Last active
June 13, 2023 17:11
-
-
Save sharadhr/add57e03e62e4e9d6ffaa24bd2485492 to your computer and use it in GitHub Desktop.
Clang-Tidy breaks with standard C++20 modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.26) | |
# Required by CMake 3.26 to enable standard C++20 module support | |
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1) | |
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API 2182bf5c-ef0d-489a-91da-49dbc3090d2a) | |
# Generate compile_commands.json | |
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | |
# Comment out the following line to disable clang-tidy; only works with Ninja. | |
# Breaks compilation when uncommented, OK when commented out. | |
set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=-*,readability-*;--extra-arg=-Xclang=-fprebuilt-module-path=${CMAKE_BINARY_DIR}/CMakeFiles/test_lib.dir/;-p=${CMAKE_BINARY_DIR}) | |
project(test LANGUAGES CXX) | |
add_library(test_lib STATIC) | |
target_sources(test_lib | |
PRIVATE | |
FILE_SET CXX_MODULES | |
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} | |
FILES | |
test.cppm) | |
target_compile_features(test_lib PUBLIC cxx_std_20) | |
add_executable(test main.cpp) | |
target_compile_features(test PUBLIC cxx_std_20) | |
target_link_libraries(test PRIVATE test_lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": 3, | |
"cmakeMinimumRequired": { | |
"major": 3, | |
"minor": 26, | |
"patch": 0 | |
}, | |
"configurePresets": [ | |
{ | |
"name": "Ninja", | |
"generator": "Ninja", | |
"binaryDir": "${sourceDir}/build", | |
"cacheVariables": { | |
"CMAKE_CXX_COMPILER": "cl.exe" | |
}, | |
"architecture": { | |
"value": "x64", | |
"strategy": "external" | |
} | |
}, | |
{ | |
"name": "MSBuild", | |
"generator": "Visual Studio 17 2022", | |
"binaryDir": "${sourceDir}/build", | |
"cacheVariables": { | |
"CMAKE_CXX_COMPILER": "cl.exe" | |
}, | |
"architecture": { | |
"value": "x64", | |
"strategy": "external" | |
} | |
} | |
], | |
"buildPresets": [ | |
{ | |
"name": "Ninja", | |
"configurePreset": "Ninja" | |
}, | |
{ | |
"name": "MSBuild", | |
"configurePreset": "MSBuild" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import test; | |
auto main() -> int { | |
return t::f(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export module test; | |
export namespace t | |
{ | |
auto f() -> int { return 1 + 5; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment