-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clang] Warn on deprecated specializations used in system headers. (#…
…70353) When the top of the instantiation stack is in user code. The goal of this PR is to allow deprecation of some char_traits specializations in libc++ as done in https://reviews.llvm.org/D157058 which was later reverted by #66153 (comment) as Clang never emitted the libc++ warnings. Because Clang likes to eagerly instantiate, we can look for the location of the top of the instantiation stack, and emit a warning if that location is in user code. The warning emission is forced by temporarily instructing the diag engine not to silence warning in system headers.
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 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
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
28 changes: 28 additions & 0 deletions
28
clang/test/SemaCXX/warn-deprecated-specializations-in-system-headers.cpp
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,28 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
||
#ifdef BE_THE_HEADER | ||
#pragma clang system_header | ||
|
||
template <typename T> | ||
struct traits; | ||
|
||
template <> | ||
struct [[deprecated]] traits<int> {}; // expected-note {{'traits<int>' has been explicitly marked deprecated here}} | ||
|
||
template<typename T, typename Trait = traits<T>> // expected-warning {{'traits<int>' is deprecated}} | ||
struct basic_string {}; | ||
|
||
// should not warn, defined and used in system headers | ||
using __do_what_i_say_not_what_i_do = traits<int> ; | ||
|
||
template<typename T, typename Trait = traits<double>> | ||
struct should_not_warn {}; | ||
|
||
#else | ||
#define BE_THE_HEADER | ||
#include __FILE__ | ||
|
||
basic_string<int> test1; // expected-note {{in instantiation of default argument for 'basic_string<int>' required here}} | ||
should_not_warn<int> test2; | ||
|
||
#endif |