1// RUN: rm -rf %t 2// RUN: mkdir -p %t 3// RUN: split-file %s %t 4// 5// Baseline testing to make sure we can detect the ODR violation from the CC1 invocation. 6// RUNX: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm 7// RUNX: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm 8// RUNX: %clang_cc1 -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -verify 9// 10// Testing that we can ignore the ODR violation from the driver invocation. 11// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm 12// RUN: %clang -std=c++20 %t/b.cppm --precompile -o %t/b.pcm 13// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify \ 14// RUN: -DIGNORE_ODR_VIOLATION 15// 16// Testing that the driver can require to check the ODR violation. 17// RUN: %clang -std=c++20 -Xclang -fno-skip-odr-check-in-gmf %t/a.cppm --precompile -o %t/a.pcm 18// RUN: %clang -std=c++20 -Xclang -fno-skip-odr-check-in-gmf %t/b.cppm --precompile -o %t/b.pcm 19// RUN: %clang -std=c++20 -Xclang -fno-skip-odr-check-in-gmf %t/test.cc -fprebuilt-module-path=%t \ 20// RUN: -fsyntax-only -Xclang -verify 21 22//--- func1.h 23bool func(int x, int y) { 24 return true; 25} 26 27//--- func2.h 28bool func(int x, int y) { 29 return false; 30} 31 32//--- a.cppm 33module; 34#include "func1.h" 35export module a; 36export using ::func; 37 38export extern "C++" bool func1() { return true; } 39 40//--- b.cppm 41module; 42#include "func2.h" 43export module b; 44export using ::func; 45 46export extern "C++" bool func1() { return false; } 47 48//--- test.cc 49import a; 50import b; 51bool test() { 52 return func(1, 2) && func1(); 53} 54 55#ifdef IGNORE_ODR_VIOLATION 56// expected-no-diagnostics 57#else 58// expected-error@func2.h:1 {{'func' has different definitions in different modules;}} 59// expected-note@func1.h:1 {{but in 'a.<global>' found a different body}} 60// expected-error@b.cppm:6 {{'func1' has different definitions in different modules; definition in module 'b.<implicit global>' first difference is function body}} 61// expected-note@a.cppm:6 {{but in 'a.<implicit global>' found a different body}} 62#endif 63