forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang][Sema] Expose static inline functions from GMF (llvm#104701)
In C, it is a common pattern to have `static inline` functions in headers to avoid ODR issues. Currently, when those headers are included in a GMF, the names are not found when two-phase name lookup and ADL is involved. Those names are removed by `Sema::AddOverloadCandidate`. Similarly, in C++, sometimes people use templates with internal linkage in headers. As the GMF was designed to be a transitional mechanism for headers, special case those functions in `Sema::AddOverloadCandidate`. This fixes <llvm#98021>.
- Loading branch information
Showing
6 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm \ | ||
// RUN: -DTEST_INLINE | ||
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify \ | ||
// RUN: -DTEST_INLINE | ||
// | ||
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm | ||
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify | ||
|
||
//--- a.h | ||
#ifdef TEST_INLINE | ||
#define INLINE inline | ||
#else | ||
#define INLINE | ||
#endif | ||
static INLINE void func(long) {} | ||
template <typename T = long> void a() { func(T{}); } | ||
|
||
//--- a.cppm | ||
module; | ||
#include "a.h" | ||
export module a; | ||
export using ::a; | ||
|
||
//--- test.cc | ||
import a; | ||
auto m = (a(), 0); | ||
|
||
#ifdef TEST_INLINE | ||
// expected-no-diagnostics | ||
#else | ||
// [email protected]:7 {{no matching function for call to 'func'}} | ||
// [email protected]:2 {{in instantiation of function template specialization 'a<long>' requested here}} | ||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm | ||
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify | ||
|
||
//--- a.h | ||
template <typename G> static inline void func() {} | ||
template <typename T = long> void a() { func<T>(); } | ||
|
||
//--- a.cppm | ||
module; | ||
#include "a.h" | ||
export module a; | ||
export using ::a; | ||
|
||
//--- test.cc | ||
import a; | ||
auto m = (a(), 0); | ||
|
||
// expected-no-diagnostics |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm | ||
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify | ||
|
||
//--- a.h | ||
namespace ns { | ||
template <typename G> static void func() {} | ||
template <typename T = long> void a() { func<T>(); } | ||
} | ||
|
||
//--- a.cppm | ||
module; | ||
#include "a.h" | ||
export module a; | ||
export using ns::a; | ||
|
||
//--- test.cc | ||
import a; | ||
auto m = (a(), 0); | ||
|
||
// expected-no-diagnostics |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm \ | ||
// RUN: -DTEST_INLINE | ||
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify \ | ||
// RUN: -DTEST_INLINE | ||
// | ||
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm | ||
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify | ||
|
||
//--- a.h | ||
#ifdef TEST_INLINE | ||
#define INLINE inline | ||
#else | ||
#define INLINE | ||
#endif | ||
namespace ns { | ||
template <typename G> static void func() {} | ||
template <> INLINE void func<long>() {} | ||
template <typename T = long> void a() { func<T>(); } | ||
} | ||
|
||
//--- a.cppm | ||
module; | ||
#include "a.h" | ||
export module a; | ||
export using ns::a; | ||
|
||
//--- test.cc | ||
import a; | ||
auto m = (a(), 0); | ||
|
||
#ifdef TEST_INLINE | ||
// expected-no-diagnostics | ||
#else | ||
// [email protected]:9 {{no matching function for call to 'func'}} | ||
// [email protected]:2 {{in instantiation of function template specialization 'ns::a<long>' requested here}} | ||
#endif |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang -std=c++20 %t/a.cppm --precompile -o %t/a.pcm | ||
// RUN: %clang -std=c++20 %t/test.cc -fprebuilt-module-path=%t -fsyntax-only -Xclang -verify | ||
|
||
//--- a.h | ||
namespace ns { | ||
namespace { | ||
template <typename G> void func() {} | ||
} | ||
template <typename T = long> void a() { func<T>(); } | ||
} | ||
|
||
//--- a.cppm | ||
module; | ||
#include "a.h" | ||
export module a; | ||
export using ns::a; | ||
|
||
//--- test.cc | ||
import a; | ||
auto m = (a(), 0); | ||
|
||
// expected-no-diagnostics |