base_macros.h disables warnings without push/pop, leaking them into consumer translation units

Ouverte
#1,624 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
1/5
Temps estimé
Moins d'une heure
Accessibilité débutants
20/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
cpp
Domaine
tooling

Piste de recherche

Inspectez strings/base_macros.h et les pragmas d’avertissement MSVC décrits dans l’issue. Reproduisez la fuite avec l’exemple leak.cpp fourni sous /W4 ou /Wall, puis vérifiez qu’après la modification les avertissements réapparaissent et que les en-têtes C++/WinRT concernés se compilent toujours proprement ; l’issue indique que cela a été corrigé dans #1625.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
C++
Étoiles
1.9k
Forks
281
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de microsoft/cppwinrt

Toutes les issues de microsoft/cppwinrt

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.