diff options
author | Reid Kleckner <rnk@google.com> | 2019-09-12 18:26:34 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2019-09-12 18:26:34 +0000 |
commit | e6202c43db54569c344e8dff98fdb399ef023c82 (patch) | |
tree | 05345ad28c5414b021b60ec75b8839314d2faed9 /lib/Sema | |
parent | 02fd9963406199172d2545389edbecc440982dc7 (diff) | |
download | clang-e6202c43db54569c344e8dff98fdb399ef023c82.tar.gz |
[MS] Warn when shadowing template parameters under -fms-compatibility
Summary:
C++ does not allow shadowing template parameters, but previously we
allowed it under -fms-extensions. Now this behavior is controlled by
-fms-compatibility, and we emit a -Wmicrosoft-template warning when it
happens.
Fixes PR43265
Reviewers: thakis, hans
Subscribers: amccarth, rsmith, STL_MSFT, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D67463
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@371753 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 001e433ad6..91466fa904 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -849,15 +849,14 @@ bool Sema::DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, void Sema::DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl) { assert(PrevDecl->isTemplateParameter() && "Not a template parameter"); - // Microsoft Visual C++ permits template parameters to be shadowed. - if (getLangOpts().MicrosoftExt) - return; - // C++ [temp.local]p4: // A template-parameter shall not be redeclared within its // scope (including nested scopes). - Diag(Loc, diag::err_template_param_shadow) - << cast<NamedDecl>(PrevDecl)->getDeclName(); + // + // Make this a warning when MSVC compatibility is requested. + unsigned DiagId = getLangOpts().MSVCCompat ? diag::ext_template_param_shadow + : diag::err_template_param_shadow; + Diag(Loc, DiagId) << cast<NamedDecl>(PrevDecl)->getDeclName(); Diag(PrevDecl->getLocation(), diag::note_template_param_here); } |