This is an archive of the discontinued LLVM Phabricator instance.

fix false positives in clang-tidy macro parentheses checker
ClosedPublic

Authored by danielmarjamaki on Jun 23 2015, 3:44 AM.

Details

Reviewers
alexfh
Summary

I got email from Robert Reif about false positive(s) for such code:

struct Fred
{
    enum Foo { First, Second };
};

const char * to_string(Fred::Foo foo, bool verbose)
{
    switch (foo)
    {
#define CASE(a, b)    case Fred::a: if (verbose) return b; else return #a
    CASE(First, "This is the first one");
    CASE(Second, "This is the second one");
#undef CASE
    }
    return "unknown";
}

The macro-parentheses checker currently warns about both macro arguments a and b. The warning about a is wrong. The warning about b is annoying.

This patch fixes so no warning is shown for that example code.

Diff Detail

Event Timeline

danielmarjamaki retitled this revision from to fix false positives in clang-tidy macro parentheses checker.
danielmarjamaki updated this object.
danielmarjamaki edited the test plan for this revision. (Show Details)
danielmarjamaki added a reviewer: alexfh.
danielmarjamaki updated this object.
danielmarjamaki added a subscriber: Unknown Object (MLST).
alexfh accepted this revision.Jun 23 2015, 3:50 AM
alexfh edited edge metadata.

LG

clang-tidy/misc/MacroParenthesesCheck.cpp
172

nit: "Assignment/return, i.e. '= x;' or 'return x;'.

This revision is now accepted and ready to land.Jun 23 2015, 3:50 AM

Committed with 240399.

BTW, I found a couple of related issues:

  1. When a parameter is used as a type or a namespace qualifier: `#define

X(type) type::Field`

  1. When a parameter is used as a type parameter of a template: `#define

X(t) std::set<t> s; ... or #define X(t) some_template<..., t, ...>`

BTW, I found a couple of related issues:

  1. When a parameter is used as a type or a namespace qualifier: `#define

X(type) type::Field`

  1. When a parameter is used as a type parameter of a template: `#define

X(t) std::set<t> s; ... or #define X(t) some_template<..., t, ...>`

thanks!

I'll look at those asap..