r321616 - Revert r321614 and r321615

2017-12-31 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Sun Dec 31 18:49:17 2017
New Revision: 321616

URL: http://llvm.org/viewvc/llvm-project?rev=321616=rev
Log:
Revert r321614 and r321615
  - the enum changes to TypeSpecifierType are breaking some tests - and will 
require a more careful integration.

Sorry about rushing these changes - thought I could sneak them in prior to 
heading out for new years ;)

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=321616=321615=321616=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Dec 31 18:49:17 2017
@@ -4747,11 +4747,11 @@ public:
   }
 
   /// Converts a type specifier (DeclSpec::TST) into an elaborated type 
keyword.
-  static ElaboratedTypeKeyword getKeywordForTypeSpec(TypeSpecifierType 
TypeSpec);
+  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
 
   /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
   /// It is an error to provide a type specifier which *isn't* a tag kind here.
-  static TagTypeKind getTagTypeKindForTypeSpec(TypeSpecifierType TypeSpec);
+  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
 
   /// Converts a TagTypeKind into an elaborated type keyword.
   static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=321616=321615=321616=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Sun Dec 31 18:49:17 2017
@@ -598,11 +598,11 @@ public:
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Sign);
 else
-  return TypeSpecifierSign::TSS_unspecified;
+  return TSS_unspecified;
   }
 
   bool hasWrittenSignSpec() const {
-return getWrittenSignSpec() != TypeSpecifierSign::TSS_unspecified;
+return getWrittenSignSpec() != TSS_unspecified;
   }
 
   void setWrittenSignSpec(TypeSpecifierSign written) {
@@ -614,11 +614,11 @@ public:
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Width);
 else
-  return TypeSpecifierWidth::TSW_unspecified;
+  return TSW_unspecified;
   }
 
   bool hasWrittenWidthSpec() const {
-return getWrittenWidthSpec() != TypeSpecifierWidth::TSW_unspecified;
+return getWrittenWidthSpec() != TSW_unspecified;
   }
 
   void setWrittenWidthSpec(TypeSpecifierWidth written) {
@@ -629,7 +629,7 @@ public:
   TypeSpecifierType getWrittenTypeSpec() const;
 
   bool hasWrittenTypeSpec() const {
-return getWrittenTypeSpec() != TypeSpecifierType::TST_unspecified;
+return getWrittenTypeSpec() != TST_unspecified;
   }
 
   void setWrittenTypeSpec(TypeSpecifierType written) {
@@ -653,9 +653,9 @@ public:
 setBuiltinLoc(Loc);
 if (needsExtraLocalData()) {
   WrittenBuiltinSpecs  = getWrittenBuiltinSpecs();
-  wbs.Sign = TypeSpecifierSign::TSS_unspecified;
-  wbs.Width = TypeSpecifierWidth::TSW_unspecified;
-  wbs.Type = TypeSpecifierType::TST_unspecified;
+  wbs.Sign = TSS_unspecified;
+  wbs.Width = TSW_unspecified;
+  wbs.Type = TST_unspecified;
   wbs.ModeAttr = false;
 }
   }

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=321616=321615=321616=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Sun Dec 31 18:49:17 2017
@@ -22,7 +22,7 @@
 
 namespace clang {
   /// \brief Specifies the width of a type, e.g., short, long, or long long.
-  enum class TypeSpecifierWidth {
+  enum TypeSpecifierWidth {
 TSW_unspecified,
 TSW_short,
 TSW_long,
@@ -30,7 +30,7 @@ namespace clang {
   };
   
  

r321615 - Add scope specifiers to updated scoped-enums (that I somehow missed in r321614)

2017-12-31 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Sun Dec 31 18:35:43 2017
New Revision: 321615

URL: http://llvm.org/viewvc/llvm-project?rev=321615=rev
Log:
Add scope specifiers to updated scoped-enums (that I somehow missed in r321614)

Modified:
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/AST/TypeLoc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypeLoc.cpp?rev=321615=321614=321615=diff
==
--- cfe/trunk/lib/AST/TypeLoc.cpp (original)
+++ cfe/trunk/lib/AST/TypeLoc.cpp Sun Dec 31 18:35:43 2017
@@ -311,19 +311,19 @@ TypeSpecifierType BuiltinTypeLoc::getWri
 return static_cast(getWrittenBuiltinSpecs().Type);
   switch (getTypePtr()->getKind()) {
   case BuiltinType::Void:
-return TST_void;
+return TypeSpecifierType::TST_void;
   case BuiltinType::Bool:
-return TST_bool;
+return TypeSpecifierType::TST_bool;
   case BuiltinType::Char_U:
   case BuiltinType::Char_S:
-return TST_char;
+return TypeSpecifierType::TST_char;
   case BuiltinType::Char16:
-return TST_char16;
+return TypeSpecifierType::TST_char16;
   case BuiltinType::Char32:
-return TST_char32;
+return TypeSpecifierType::TST_char32;
   case BuiltinType::WChar_S:
   case BuiltinType::WChar_U:
-return TST_wchar;
+return TypeSpecifierType::TST_wchar;
   case BuiltinType::UChar:
   case BuiltinType::UShort:
   case BuiltinType::UInt:
@@ -365,7 +365,7 @@ TypeSpecifierType BuiltinTypeLoc::getWri
   case BuiltinType::OCLReserveID:
   case BuiltinType::BuiltinFn:
   case BuiltinType::OMPArraySection:
-return TST_unspecified;
+return TypeSpecifierType::TST_unspecified;
   }
 
   llvm_unreachable("Invalid BuiltinType Kind!");

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=321615=321614=321615=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun Dec 31 18:35:43 2017
@@ -590,9 +590,9 @@ void TypeLocWriter::VisitQualifiedTypeLo
 void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
   Record.AddSourceLocation(TL.getBuiltinLoc());
   if (TL.needsExtraLocalData()) {
-Record.push_back(TL.getWrittenTypeSpec());
-Record.push_back(TL.getWrittenSignSpec());
-Record.push_back(TL.getWrittenWidthSpec());
+Record.push_back(static_cast(TL.getWrittenTypeSpec()));
+Record.push_back(static_cast(TL.getWrittenSignSpec()));
+Record.push_back(static_cast(TL.getWrittenWidthSpec()));
 Record.push_back(TL.hasModeAttr());
   }
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321614 - [NFC] Modernize enums TypeSpecifierWidth, TypeSpecifierSign & TypeSpecifierType into scoped enums.

2017-12-31 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Sun Dec 31 18:19:52 2017
New Revision: 321614

URL: http://llvm.org/viewvc/llvm-project?rev=321614=rev
Log:
[NFC] Modernize enums TypeSpecifierWidth, TypeSpecifierSign & TypeSpecifierType 
into scoped enums.

  

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=321614=321613=321614=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Dec 31 18:19:52 2017
@@ -4747,11 +4747,11 @@ public:
   }
 
   /// Converts a type specifier (DeclSpec::TST) into an elaborated type 
keyword.
-  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
+  static ElaboratedTypeKeyword getKeywordForTypeSpec(TypeSpecifierType 
TypeSpec);
 
   /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
   /// It is an error to provide a type specifier which *isn't* a tag kind here.
-  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
+  static TagTypeKind getTagTypeKindForTypeSpec(TypeSpecifierType TypeSpec);
 
   /// Converts a TagTypeKind into an elaborated type keyword.
   static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=321614=321613=321614=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Sun Dec 31 18:19:52 2017
@@ -598,11 +598,11 @@ public:
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Sign);
 else
-  return TSS_unspecified;
+  return TypeSpecifierSign::TSS_unspecified;
   }
 
   bool hasWrittenSignSpec() const {
-return getWrittenSignSpec() != TSS_unspecified;
+return getWrittenSignSpec() != TypeSpecifierSign::TSS_unspecified;
   }
 
   void setWrittenSignSpec(TypeSpecifierSign written) {
@@ -614,11 +614,11 @@ public:
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Width);
 else
-  return TSW_unspecified;
+  return TypeSpecifierWidth::TSW_unspecified;
   }
 
   bool hasWrittenWidthSpec() const {
-return getWrittenWidthSpec() != TSW_unspecified;
+return getWrittenWidthSpec() != TypeSpecifierWidth::TSW_unspecified;
   }
 
   void setWrittenWidthSpec(TypeSpecifierWidth written) {
@@ -629,7 +629,7 @@ public:
   TypeSpecifierType getWrittenTypeSpec() const;
 
   bool hasWrittenTypeSpec() const {
-return getWrittenTypeSpec() != TST_unspecified;
+return getWrittenTypeSpec() != TypeSpecifierType::TST_unspecified;
   }
 
   void setWrittenTypeSpec(TypeSpecifierType written) {
@@ -653,9 +653,9 @@ public:
 setBuiltinLoc(Loc);
 if (needsExtraLocalData()) {
   WrittenBuiltinSpecs  = getWrittenBuiltinSpecs();
-  wbs.Sign = TSS_unspecified;
-  wbs.Width = TSW_unspecified;
-  wbs.Type = TST_unspecified;
+  wbs.Sign = TypeSpecifierSign::TSS_unspecified;
+  wbs.Width = TypeSpecifierWidth::TSW_unspecified;
+  wbs.Type = TypeSpecifierType::TST_unspecified;
   wbs.ModeAttr = false;
 }
   }

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=321614=321613=321614=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Sun Dec 31 18:19:52 2017
@@ -22,7 +22,7 @@
 
 namespace clang {
   /// \brief Specifies the width of a type, e.g., short, long, or long long.
-  enum TypeSpecifierWidth {
+  enum class TypeSpecifierWidth {
 TSW_unspecified,
 TSW_short,
 TSW_long,
@@ -30,7 +30,7 @@ namespace clang {
   };
   
   /// \brief Specifies the signedness of a type, e.g., signed or unsigned.
-  enum TypeSpecifierSign {
+  enum class TypeSpecifierSign {
 TSS_unspecified,
 TSS_signed,
 TSS_unsigned
@@ -42,7 +42,7 @@ namespace 

[PATCH] D41646: [Sema] Improve diagnostics for const- and ref-qualified member functions

2017-12-31 Thread Jacob Bandes-Storch via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321609: [Sema] Improve diagnostics for const- and 
ref-qualified member functions (authored by jtbandes, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41646

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
  cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
  cfe/trunk/test/SemaCXX/copy-initialization.cpp
  cfe/trunk/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp
  cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp

Index: cfe/trunk/lib/Sema/SemaOverload.cpp
===
--- cfe/trunk/lib/Sema/SemaOverload.cpp
+++ cfe/trunk/lib/Sema/SemaOverload.cpp
@@ -5145,7 +5145,8 @@
   *this, From->getLocStart(), From->getType(), FromClassification, Method,
   Method->getParent());
   if (ICS.isBad()) {
-if (ICS.Bad.Kind == BadConversionSequence::bad_qualifiers) {
+switch (ICS.Bad.Kind) {
+case BadConversionSequence::bad_qualifiers: {
   Qualifiers FromQs = FromRecordType.getQualifiers();
   Qualifiers ToQs = DestType.getQualifiers();
   unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
@@ -5158,10 +5159,28 @@
   << Method->getDeclName();
 return ExprError();
   }
+  break;
+}
+
+case BadConversionSequence::lvalue_ref_to_rvalue:
+case BadConversionSequence::rvalue_ref_to_lvalue: {
+  bool IsRValueQualified =
+Method->getRefQualifier() == RefQualifierKind::RQ_RValue;
+  Diag(From->getLocStart(), diag::err_member_function_call_bad_ref)
+<< Method->getDeclName() << FromClassification.isRValue()
+<< IsRValueQualified;
+  Diag(Method->getLocation(), diag::note_previous_decl)
+<< Method->getDeclName();
+  return ExprError();
+}
+
+case BadConversionSequence::no_conversion:
+case BadConversionSequence::unrelated_class:
+  break;
 }
 
 return Diag(From->getLocStart(),
-diag::err_implicit_object_parameter_init)
+diag::err_member_function_call_bad_type)
<< ImplicitParamRecordType << FromRecordType << From->getSourceRange();
   }
 
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1589,12 +1589,20 @@
 def ext_pure_function_definition : ExtWarn<
   "function definition with pure-specifier is a Microsoft extension">,
   InGroup;
-def err_implicit_object_parameter_init : Error<
-  "cannot initialize object parameter of type %0 with an expression "
-  "of type %1">;
 def err_qualified_member_of_unrelated : Error<
   "%q0 is not a member of class %1">;
 
+def err_member_function_call_bad_cvr : Error<
+  "'this' argument to member function %0 has type %1, but function is not marked "
+  "%select{const|restrict|const or restrict|volatile|const or volatile|"
+  "volatile or restrict|const, volatile, or restrict}2">;
+def err_member_function_call_bad_ref : Error<
+  "'this' argument to member function %0 is an %select{lvalue|rvalue}1, "
+  "but function has %select{non-const lvalue|rvalue}2 ref-qualifier">;
+def err_member_function_call_bad_type : Error<
+  "cannot initialize object parameter of type %0 with an expression "
+  "of type %1">;
+
 def warn_call_to_pure_virtual_member_function_from_ctor_dtor : Warning<
   "call to pure virtual member function %0 has undefined behavior; "
   "overrides of %0 in subclasses are not available in the "
@@ -1815,10 +1823,6 @@
 def err_init_list_bad_dest_type : Error<
   "%select{|non-aggregate }0type %1 cannot be initialized with an initializer "
   "list">;
-def err_member_function_call_bad_cvr : Error<"member function %0 not viable: "
-"'this' argument has type %1, but function is not marked "
-"%select{const|restrict|const or restrict|volatile|const or volatile|"
-"volatile or restrict|const, volatile, or restrict}2">;
 
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "
Index: cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
===
--- cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
+++ cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -std=c++2a %s -verify
 
 struct X {
-  void ref() & {}
+  void ref() & {} // expected-note{{'ref' declared here}}
   void cref() const& {}
 };
 
 void test() {
-  X{}.ref(); // expected-error{{cannot initialize object parameter of type 'X' with an expression of type 'X'}}
+  X{}.ref(); // expected-error{{'this' argument to member function 'ref' is an rvalue, but function has 

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2017-12-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D41648#965437, @JonasToth wrote:

> In https://reviews.llvm.org/D41648#965432, @aaron.ballman wrote:
>
> > I think this check is going to be extraordinarily chatty. For instance, 
> > macros are often used to hide compiler details in signatures, such as use 
> > of attributes. This construct cannot be replaced with anything else because 
> > the macro isn't defining an object or value. Another example where this 
> > will be bad is for conditional processing where the macro is later used in 
> > a `#if`, `#elif`, `#ifdef`, or `#ifndef` preprocessor conditional, as this 
> > also cannot be replaced with a `constexpr` variable. Without handling 
> > things like this, I don't see how this rule can provide utility to real 
> > world code. Do you have ideas for how to handle these kind of situations?
>
>
> The check will only warn in the definition of the macro not the expansion.


I understand. It's the definitions I am concerned about.

> The guidelines are really strict with macros and explicitly state that 
> program maniupulation is a bad thing.

Yes, and I'm saying that the guidelines aren't useful for real code bases 
because they restrict more than is reasonable. So while I think the check is 
largely implementing what the guidelines recommend, I think that some of these 
scenarios should be brought back to the guideline authors to weigh in on before 
we expose the check to users.

> Having a macro without value, like header guards or compile time flag style 
> things are not reported with this check.
> 
> Other (valid) use cases require a NOLINT with this check. But i do not know 
> how to figure out automatically what a macro is meant to do. I can introduce 
> a whitelist for allowed macros.
>  Furthermore i could make each use case a configurable option. E.g. 
> forbidding constant definitions i still a good thing (imho).

I don't think a whitelist is going to cut it here -- users are not going to try 
to figure out every conditional compilation or attribute macro definition used 
in their large code base; they'll simply disable the check as not being overly 
useful. For example, look at Compiler.h in LLVM and try to see how you would 
rewrite that code to perform the same purposes without triggering diagnostics 
from this check. That sort of file is common to almost every production code 
base I've ever come across.

One way to make this less chatty would be to check whether the macro 
replacement list is defining a source construct that cannot be replaced by 
constexpr variables or inline functions (such as LLVM_ATTRIBUTE_ALWAYS_INLINE). 
If we had whole-program analysis, I think we could do something further like 
scan the uses of the macros to determine whether they're used for conditional 
compilation (such as LLVM_ENABLE_EXCEPTIONS). However, I have no idea how we 
would handle cases like LLVM_LIKELY and LLVM_UNLIKELY, but expecting users to 
NOLINT 500+ lines of common macro code doesn't seem like a good first approach. 
I'd be curious to know what the C++ Core Guidelines folks think about those use 
cases and how they would recommend rewriting the code to adhere to their 
guidelines. Do they really expect users to use *no* macros in C++ code outside 
of header include guards and noop definitions even when asked about reasonable 
use cases like cross-compiler attributes or builtins? I mean, many of these 
things cannot even use the attribute the C++ Core Guidelines require for 
silencing such diagnostics -- how do they want to use gsl::suppress to silence 
a diagnostic on a macro definition?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2017-12-31 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In https://reviews.llvm.org/D41648#965432, @aaron.ballman wrote:

> I think this check is going to be extraordinarily chatty. For instance, 
> macros are often used to hide compiler details in signatures, such as use of 
> attributes. This construct cannot be replaced with anything else because the 
> macro isn't defining an object or value. Another example where this will be 
> bad is for conditional processing where the macro is later used in a `#if`, 
> `#elif`, `#ifdef`, or `#ifndef` preprocessor conditional, as this also cannot 
> be replaced with a `constexpr` variable. Without handling things like this, I 
> don't see how this rule can provide utility to real world code. Do you have 
> ideas for how to handle these kind of situations?


The check will only warn in the definition of the macro not the expansion. The 
guidelines are really strict with macros and explicitly state that program 
maniupulation is a bad thing.
Having a macro without value, like header guards or compile time flag style 
things are not reported with this check.

Other (valid) use cases require a NOLINT with this check. But i do not know how 
to figure out automatically what a macro is meant to do. I can introduce a 
whitelist for allowed macros.
Furthermore i could make each use case a configurable option. E.g. forbidding 
constant definitions i still a good thing (imho).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321592 - [Sema] Improve diagnostics for const- and ref-qualified member functions

2017-12-31 Thread Jacob Bandes-Storch via cfe-commits
Author: jtbandes
Date: Sat Dec 30 20:49:39 2017
New Revision: 321592

URL: http://llvm.org/viewvc/llvm-project?rev=321592=rev
Log:
[Sema] Improve diagnostics for const- and ref-qualified member functions

Summary:
Adjust wording for const-qualification mismatch to be a little more clear.

Also add another diagnostic for a ref qualifier mismatch, which previously 
produced a useless error (this error path is simply very old; see rL119336):

Before:
  error: cannot initialize object parameter of type 'X0' with an expression of 
type 'X0'

After:
  error: 'this' argument to member function 'rvalue' is an lvalue, but function 
has rvalue ref-qualifier

Reviewers: rsmith, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, aaron.ballman, cfe-commits

Differential Revision: https://reviews.llvm.org/D39937

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
cfe/trunk/test/SemaCXX/copy-initialization.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=321592=321591=321592=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Dec 30 20:49:39 
2017
@@ -1589,12 +1589,20 @@ def err_non_virtual_pure : Error<
 def ext_pure_function_definition : ExtWarn<
   "function definition with pure-specifier is a Microsoft extension">,
   InGroup;
-def err_implicit_object_parameter_init : Error<
-  "cannot initialize object parameter of type %0 with an expression "
-  "of type %1">;
 def err_qualified_member_of_unrelated : Error<
   "%q0 is not a member of class %1">;
 
+def err_member_function_call_bad_cvr : Error<
+  "'this' argument to member function %0 has type %1, but function is not 
marked "
+  "%select{const|restrict|const or restrict|volatile|const or volatile|"
+  "volatile or restrict|const, volatile, or restrict}2">;
+def err_member_function_call_bad_ref : Error<
+  "'this' argument to member function %0 is an %select{lvalue|rvalue}1, "
+  "but function has %select{non-const lvalue|rvalue}2 ref-qualifier">;
+def err_member_function_call_bad_type : Error<
+  "cannot initialize object parameter of type %0 with an expression "
+  "of type %1">;
+
 def warn_call_to_pure_virtual_member_function_from_ctor_dtor : Warning<
   "call to pure virtual member function %0 has undefined behavior; "
   "overrides of %0 in subclasses are not available in the "
@@ -1815,10 +1823,6 @@ def warn_temporary_array_to_pointer_deca
 def err_init_list_bad_dest_type : Error<
   "%select{|non-aggregate }0type %1 cannot be initialized with an initializer "
   "list">;
-def err_member_function_call_bad_cvr : Error<"member function %0 not viable: "
-"'this' argument has type %1, but function is not marked "
-"%select{const|restrict|const or restrict|volatile|const or volatile|"
-"volatile or restrict|const, volatile, or restrict}2">;
 
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=321592=321591=321592=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat Dec 30 20:49:39 2017
@@ -5145,7 +5145,8 @@ Sema::PerformObjectArgumentInitializatio
   *this, From->getLocStart(), From->getType(), FromClassification, Method,
   Method->getParent());
   if (ICS.isBad()) {
-if (ICS.Bad.Kind == BadConversionSequence::bad_qualifiers) {
+switch (ICS.Bad.Kind) {
+case BadConversionSequence::bad_qualifiers: {
   Qualifiers FromQs = FromRecordType.getQualifiers();
   Qualifiers ToQs = DestType.getQualifiers();
   unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
@@ -5158,10 +5159,28 @@ Sema::PerformObjectArgumentInitializatio
   << Method->getDeclName();
 return ExprError();
   }
+  break;
+}
+
+case BadConversionSequence::lvalue_ref_to_rvalue:
+case BadConversionSequence::rvalue_ref_to_lvalue: {
+  bool IsRValueQualified =
+Method->getRefQualifier() == RefQualifierKind::RQ_RValue;
+  Diag(From->getLocStart(), diag::err_member_function_call_bad_ref)
+<< Method->getDeclName() << FromClassification.isRValue()
+<< IsRValueQualified;
+  Diag(Method->getLocation(), diag::note_previous_decl)
+<< Method->getDeclName();
+  return ExprError();
+}
+
+case BadConversionSequence::no_conversion:
+case BadConversionSequence::unrelated_class:
+  break;
 }
 
 return Diag(From->getLocStart(),
-

r321593 - Reverted 321592: [Sema] Improve diagnostics for const- and ref-qualified member functions

2017-12-31 Thread Jacob Bandes-Storch via cfe-commits
Author: jtbandes
Date: Sat Dec 30 21:13:03 2017
New Revision: 321593

URL: http://llvm.org/viewvc/llvm-project?rev=321593=rev
Log:
Reverted 321592: [Sema] Improve diagnostics for const- and ref-qualified member 
functions

A few tests need to be fixed


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
cfe/trunk/test/SemaCXX/copy-initialization.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=321593=321592=321593=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Dec 30 21:13:03 
2017
@@ -1589,19 +1589,11 @@ def err_non_virtual_pure : Error<
 def ext_pure_function_definition : ExtWarn<
   "function definition with pure-specifier is a Microsoft extension">,
   InGroup;
-def err_qualified_member_of_unrelated : Error<
-  "%q0 is not a member of class %1">;
-
-def err_member_function_call_bad_cvr : Error<
-  "'this' argument to member function %0 has type %1, but function is not 
marked "
-  "%select{const|restrict|const or restrict|volatile|const or volatile|"
-  "volatile or restrict|const, volatile, or restrict}2">;
-def err_member_function_call_bad_ref : Error<
-  "'this' argument to member function %0 is an %select{lvalue|rvalue}1, "
-  "but function has %select{non-const lvalue|rvalue}2 ref-qualifier">;
-def err_member_function_call_bad_type : Error<
+def err_implicit_object_parameter_init : Error<
   "cannot initialize object parameter of type %0 with an expression "
   "of type %1">;
+def err_qualified_member_of_unrelated : Error<
+  "%q0 is not a member of class %1">;
 
 def warn_call_to_pure_virtual_member_function_from_ctor_dtor : Warning<
   "call to pure virtual member function %0 has undefined behavior; "
@@ -1823,6 +1815,10 @@ def warn_temporary_array_to_pointer_deca
 def err_init_list_bad_dest_type : Error<
   "%select{|non-aggregate }0type %1 cannot be initialized with an initializer "
   "list">;
+def err_member_function_call_bad_cvr : Error<"member function %0 not viable: "
+"'this' argument has type %1, but function is not marked "
+"%select{const|restrict|const or restrict|volatile|const or volatile|"
+"volatile or restrict|const, volatile, or restrict}2">;
 
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=321593=321592=321593=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sat Dec 30 21:13:03 2017
@@ -5145,8 +5145,7 @@ Sema::PerformObjectArgumentInitializatio
   *this, From->getLocStart(), From->getType(), FromClassification, Method,
   Method->getParent());
   if (ICS.isBad()) {
-switch (ICS.Bad.Kind) {
-case BadConversionSequence::bad_qualifiers: {
+if (ICS.Bad.Kind == BadConversionSequence::bad_qualifiers) {
   Qualifiers FromQs = FromRecordType.getQualifiers();
   Qualifiers ToQs = DestType.getQualifiers();
   unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
@@ -5159,28 +5158,10 @@ Sema::PerformObjectArgumentInitializatio
   << Method->getDeclName();
 return ExprError();
   }
-  break;
-}
-
-case BadConversionSequence::lvalue_ref_to_rvalue:
-case BadConversionSequence::rvalue_ref_to_lvalue: {
-  bool IsRValueQualified =
-Method->getRefQualifier() == RefQualifierKind::RQ_RValue;
-  Diag(From->getLocStart(), diag::err_member_function_call_bad_ref)
-<< Method->getDeclName() << FromClassification.isRValue()
-<< IsRValueQualified;
-  Diag(Method->getLocation(), diag::note_previous_decl)
-<< Method->getDeclName();
-  return ExprError();
-}
-
-case BadConversionSequence::no_conversion:
-case BadConversionSequence::unrelated_class:
-  break;
 }
 
 return Diag(From->getLocStart(),
-diag::err_member_function_call_bad_type)
+diag::err_implicit_object_parameter_init)
<< ImplicitParamRecordType << FromRecordType << From->getSourceRange();
   }
 

Modified: cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp?rev=321593=321592=321593=diff
==
--- cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp (original)
+++ cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp Sat Dec 30 

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2017-12-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I think this check is going to be extraordinarily chatty. For instance, macros 
are often used to hide compiler details in signatures, such as use of 
attributes. This construct cannot be replaced with anything else because the 
macro isn't defining an object or value. Another example where this will be bad 
is for conditional processing where the macro is later used in a `#if`, 
`#elif`, `#ifdef`, or `#ifndef` preprocessor conditional, as this also cannot 
be replaced with a `constexpr` variable. Without handling things like this, I 
don't see how this rule can provide utility to real world code. Do you have 
ideas for how to handle these kind of situations?




Comment at: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp:21
+public:
+  MacroUsageCallbacks(MacroUsageCheck *Check) : Check{Check} {}
+  void MacroDefined(const Token ,

I'd use `Check(Check)` instead of curly braces.



Comment at: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp:28
+
+Check->warnMacro(MD);
+  }

I don't think this warning would be appropriate in all language modes. For 
instance, macros in C code, or in C++98 mode, etc.



Comment at: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp:42
+void MacroUsageCheck::warnMacro(const MacroDirective *MD) {
+  std::string DiagnosticMessage = "don't use macros to declare constants";
+

These diagnostics should be reworded to not use contractions and instead 
explain what the issue is. e.g., macro used to define a constant; consider 
using 'constexpr' instead (or something along those lines).



Comment at: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp:44
+
+  auto *Info = MD->getMacroInfo();
+  if (Info->isFunctionLike())

Don't use `auto`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2017-12-31 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 128373.
JonasToth added a comment.

- remove unneeded includes


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -125,6 +125,12 @@
   a memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
   ``alloca()``) or the ``new[]`` operator in `C++`.
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `cppcoreguidelines-owning-memory `_ check 
 
   This check implements the type-based semantic of ``gsl::owner``, but without
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h
@@ -0,0 +1,38 @@
+//===--- MacroUsageCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+
+#include "../ClangTidy.h"
+#include "clang/Lex/Preprocessor.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+enum class MacroUsageMode { Constant, Function, Variadic };
+/// Find macro usage that is considered problematic because better language
+/// constructs exist for the task.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html
+class MacroUsageCheck : public ClangTidyCheck {
+public:
+  MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(CompilerInstance ) override;
+  void warnMacro(const MacroDirective *MD);
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
@@ -0,0 +1,55 @@
+//===--- MacroUsageCheck.cpp - clang-tidy--===//
+//
+// The 

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2017-12-31 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 128372.
JonasToth added a comment.

- merge with local repos


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -125,6 +125,12 @@
   a memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
   ``alloca()``) or the ``new[]`` operator in `C++`.
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `cppcoreguidelines-owning-memory `_ check 
 
   This check implements the type-based semantic of ``gsl::owner``, but without
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h
@@ -0,0 +1,38 @@
+//===--- MacroUsageCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+
+#include "../ClangTidy.h"
+#include "clang/Lex/Preprocessor.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+enum class MacroUsageMode { Constant, Function, Variadic };
+/// Find macro usage that is considered problematic because better language
+/// constructs exist for the task.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html
+class MacroUsageCheck : public ClangTidyCheck {
+public:
+  MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(CompilerInstance ) override;
+  void warnMacro(const MacroDirective *MD);
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
@@ -0,0 +1,62 @@
+//===--- MacroUsageCheck.cpp - clang-tidy--===//
+//
+// The LLVM 

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2017-12-31 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth created this revision.
JonasToth added reviewers: aaron.ballman, hokein, alexfh.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, mgorny, nemanjai, 
klimek.

In short macros are discouraged by multiple rules (and sometimes reference 
randomly).
This check allows only headerguards and empty macros for annotation.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -125,6 +125,12 @@
   a memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
   ``alloca()``) or the ``new[]`` operator in `C++`.
 
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
+
 - New `cppcoreguidelines-owning-memory `_ check 
 
   This check implements the type-based semantic of ``gsl::owner``, but without
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h
@@ -0,0 +1,38 @@
+//===--- MacroUsageCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+
+#include "../ClangTidy.h"
+#include "clang/Lex/Preprocessor.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+enum class MacroUsageMode { Constant, Function, Variadic };
+/// Find macro usage that is considered problematic because better language
+/// constructs exist for the task.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html
+class MacroUsageCheck : public ClangTidyCheck {
+public:
+  MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(CompilerInstance ) override;
+  void warnMacro(const MacroDirective *MD);
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp

[PATCH] D41646: [Sema] Improve diagnostics for const- and ref-qualified member functions

2017-12-31 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!  Btw, if you get the LG on a patch but the patch breaks bots on commit, 
you generally don't need to do another round of review unless you need to 
highlight significant changes. You can revert the commit to get the bot to 
green, make your changes offline, and resubmit when ready.


Repository:
  rC Clang

https://reviews.llvm.org/D41646



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits