[cfe-dev] Don't help the compiler!

Benjamin Kramer benny.kra at gmail.com
Fri Jan 23 08:46:30 PST 2015


> On 23.01.2015, at 17:32, Csaba Raduly <rcsaba at gmail.com> wrote:
> 
> Hi all,
> STL (Stephan T. Lavavej) in his talk at Going Native 2013, gave this
> example of an attempt to "help the compiler", which is at best
> superfluous:
> 
>    auto p = std::make_pair<int, double>(42, 3.1415);
> 
> and recommended
> 
>    auto p = std::make_pair             (42, 3.1415);
> 
> I thought of writing a plugin to warn in the "helpful" case. However,
> clang -std=c++11 -Xclang -ast-dump produced virtually identical output.
> 
> Is there a way to distinguish between these two situations?

You can check the hasExplicitTemplateArgs bit on the DeclRefExpr to std::make_pair. We also have a clang-tidy checker for this pattern in ExplicitMakePairCheck.cpp that you can use as an example.

- Ben





More information about the cfe-dev mailing list