microsoft / microsoft/cppwinrt
base_macros.h disables warnings without push/pop, leaking them into consumer translation units
Nessuno ha ancora preso questa issue.
- Lingua principale
- C++
- Stelle
- 1.9k
- Fork
- 281
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Description
strings/base_macros.h disables four MSVC warnings with bare #pragma warning(disable: ...) and no matching push / pop:
#ifdef _MSC_VER
// Note: this is a workaround for a false-positive warning produced by the Visual C++ 15.9 compiler.
#pragma warning(disable : 5046)
// Note: this is a workaround for a false-positive warning produced by the Visual C++ 16.3 compiler.
#pragma warning(disable : 4268)
// C++ module warnings by /W4
#pragma warning(disable : 4499)
#pragma warning(disable : 4630)
#endif // _MSC_VER
base.h includes base_macros.h near the top and never restores the warning state. C5046, C4268, C4499 and C4630 therefore stay disabled for the remainder of every translation unit that includes <winrt/base.h>, which includes all of the consumer's own code that follows the include.
The first two disables are documented as workarounds for Visual C++ 15.9 and 16.3, while the latter two were added for early C++ module support. Current supported toolsets no longer emit these warnings for C++/WinRT, so retaining the pragmas only suppresses diagnostics in consumer code.
Repro
// leak.cpp
namespace { struct S { int x; }; }
S f();
int main() { f(); return 0; }
cl /c /std:c++20 /permissive- /W4 leak.cpp
leak.cpp(3): warning C5046: 'f': Symbol involving type with internal linkage not defined
Add the include and the warning disappears, even though the offending code is unchanged and is entirely outside C++/WinRT:
#include <winrt/base.h>
namespace { struct S { int x; }; }
S f();
int main() { f(); return 0; }
cl /c /std:c++20 /permissive- /W4 /I<sdk> leak.cpp
(no diagnostics)
Reproduced with both /W4 and /Wall on MSVC x64.
This is the only unscoped suppression in the tree
Auditing every warning pragma under strings/:
| header | MSVC push / pop / disable | clang push / pop / ignored |
|---|---|---|
| base_activation.h | 1 / 1 / 1 | 1 / 1 / 1 |
| base_composable.h | 1 / 1 / 1 | - |
| base_delegate.h | 1 / 1 / 1 | - |
| base_error.h | - | 1 / 1 / 1 |
| base_fast_forward.h | - | 1 / 1 / 1 |
| base_implements.h | 1 / 1 / 1 | 1 / 1 / 1 |
| base_macros.h | 0 / 0 / 4 | - |
Every other suppression in the project is already correctly scoped, so this looks like an oversight rather than a deliberate choice.
Fix
Remove all four obsolete disables from base_macros.h. This fixes every inclusion path uniformly and avoids adding warning-state plumbing for diagnostics that current compilers no longer produce.
The official MSVC off-by-default warning list does not include any of the four warning numbers. A rich generated-header translation unit compiles under /Wall with both v143 and v145 without any of them, and the v145 named-module target also rebuilds under /Wall without any of them. The original consumer repro reports C5046 again.
Fixed in #1625.
Relationship to #1623
#1623 adds a file-level diagnostic scope to every generated header, which would incidentally contain these disables inside base.h as a side effect. I am raising and fixing this separately because it is a distinct bug with its own repro, and because it should be fixed whether or not #1623 is taken.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Esamina strings/base_macros.h e le direttive pragma degli avvisi MSVC descritte nell’issue. Riproduci la perdita con l’esempio leak.cpp fornito usando /W4 o /Wall, quindi verifica che dopo la modifica gli avvisi ricompaiano e che gli header C++/WinRT pertinenti continuino a compilarsi senza errori; l’issue indica che questo problema è stato risolto in #1625.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 20/100