Issue |
91690
|
Summary |
Using Clang-Tidy breaks build with C++ 20 modules.
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
AdityaShantanu
|
**Repro:**
I have 3 files.
- cmakeCppModules.cpp
- Printers.ixx
- CMakeLists.txt
Adding this line:
```
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-checks=cppcoreguidelines-avoid-goto; # adjust to suit your needs
-warnings-as-errors=*; # treat all warnings as errors
)
```
into CMakeList.txt breaks the build. **Remove it and it builds fine.**
Error:
```
C:\repos\eng-exp-foundation\src\experimental\cmakeCppModules\build>cmake --build .
[0/1] Re-running CMake...-- Configuring done (0.1s)
-- Generating done (0.0s)
-- Build files have been written to: C:/repos/eng-exp-foundation/src/experimental/cmakeCppModules/build
[3/7] Building CXX object CMakeFiles\modules_lib.dir\Printers.ixx.obj
FAILED: CMakeFiles/modules_lib.dir/Printers.ixx.obj CMakeFiles/modules_lib.dir/Printers.ifc
"C:\Program Files\CMake\bin\cmake.exe" -E __run_co_compile --tidy=clang-tidy;-checks=cppcoreguidelines-avoid-goto;-warnings-as-errors=*;--extra-arg-before=--driver-mode=cl --source=C:\repos\eng-exp-foundation\src\experimental\cmakeCppModules\Printers.ixx -- C:\PROGRA~1\MIB055~1\2022\ENTERP~1\VC\Tools\MSVC\1439~1.335\bin\Hostx64\x64\cl.exe /nologo /TP /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++latest -MDd -Zi /showIncludes @CMakeFiles\modules_lib.dir\Printers.ixx.obj.modmap /FoCMakeFiles\modules_lib.dir\Printers.ixx.obj /FdCMakeFiles\modules_lib.dir\modules_lib.pdb /FS -c C:\repos\eng-exp-foundation\src\experimental\cmakeCppModules\Printers.ixx
error: unable to handle compilation, expected exactly one compiler job in '' [clang-diagnostic-error]
error: C:\repos\eng-exp-foundation\src\experimental\cmakeCppModules\Printers.ixx: 'linker' input unused [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
error: argument unused during compilation: '-MDd' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
error: argument unused during compilation: '-Zi' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
error: argument unused during compilation: '-c' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
error: argument unused during compilation: '-std:c++latest' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]
Error while processing C:\repos\eng-exp-foundation\src\experimental\cmakeCppModules\Printers.ixx.
5 warnings treated as errors
ninja: build stopped: subcommand failed.
```
Files:
```
# CMakeList.txt : CMake project for cmakeCppModules, include source and define
# project specific logic here.
#
# set(CMAKE_CXX_COMPILER clang++)
cmake_minimum_required (VERSION 3.28)
project (cmakeCppModules CXX)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_CLANG_TIDY
clang-tidy;
-checks=cppcoreguidelines-avoid-goto; # adjust to suit your needs
-warnings-as-errors=*; # treat all warnings as errors
)
add_library(modules_lib)
target_sources(modules_lib PUBLIC FILE_SET CXX_MODULES FILES Printers.ixx)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
if(CMAKE_BUILD_TYPE STREQUAL Debug)
if(MSVC)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} /Zi)
else()
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -g)
endif()
elseif(CMAKE_BUILD_TYPE STREQUAL Release)
add_compile_options(-O3)
endif()
# Add source to this project's executable.
add_executable (cmakeCppModules cmakeCppModules.cpp)
target_link_libraries(cmakeCppModules modules_lib)
```
```
// cmakeCppModules.cpp : Defines the entry point for the application.
//
// Conventional #includes and module imports can be freely mixed.
#include vector
// Import the Printers module defined in Printers.ixx.
import Printers;
using namespace std;
void print_vector(const vectorint list) {
// SimplePrinter and get_default_printer are imported from the
// Printers module.
SimplePrinter printer = get_default_printer();
for (auto i : list) {
printer.print_element(i);
}
printer.print_separator();
}
int main() {
const vectorint vec = {1, 2, 3, 4, 5};
print_vector(vec);
return 0;
}
```
```
// Printers.ixx
//
// The .ixx extension lets the build system know this file contains
// a module interface.
// Begin global module fragment.
module;
// Headers included in the global module fragment (between module; and
// export module Printers;) can be used by the module implementation but
// are not exported. These included headers are invisible to translation
// units that import the Printers module.
#include iostream
// Creates the Printers module. This can be imported into other translation
// units with import Printers; Any items marked with the export keyword
// will be available in translation units that import the Printers module.
export module Printers;
// This only applies to this module's translation unit. It does not leak
// into translation units that import the Printers module.
using namespace std;
// These constants are not exported, they are invisible from translation
// units that import the Printer module.
const string default_spacer = ;
const string default_separator = ,\n;
// SimplePrinter is exported and accessible to any code that imports the
// Printers module.
export struct SimplePrinter {
string element_spacer;
string separator;
void print_element(int e) { std::cout e element_spacer; }
void print_separator() { std::cout separator; }
};
// Exports the function get_default_printer.
// This is accessible from translation units that import the Printers module.
export SimplePrinter get_default_printer() {
// while (1) {
// goto dummy_label;
// }
// dummy_label:
return SimplePrinter{.element_spacer = default_spacer, .separator = default_separator};
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs