[PATCH] D67460: clang-tidy: modernize-use-using work with multi-argument templates

Jonathan Meier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 12 05:08:33 PDT 2019


jonathanmeier added a comment.

Unfortunately, only considering parenthesis (`l_paren`, `r_paren`) is not sufficient. We need to consider all the nesting tokens, including brackets (`l_square`, `r_square`) and braces (`l_brace`, `r_brace`), since the Standard says (C++ 17 Draft N4659, Section 17.2/3 <https://timsong-cpp.github.io/cppwp/n4659/temp.names#3>):

> [...] When parsing a template-argument-list, the first non-nested > is taken as the ending delimiter rather than a greater-than operator. [...]

Example with brackets that fails with your updated patch:

  template <bool B>
  struct S {};
  
  constexpr bool b[1] = { true };
  
  typedef S<b[0 < 0]> S_t, *S_p;

The following is an example with braces inside a template argument:

  struct T {
    constexpr T(bool) {}
    
    static constexpr bool b = true;  
  };
  
  typedef S<T{ 0 < 0 }.b> S_t, *S_p;

Note though, that the current code aborts upon encountering braces to avoid removing a `typedef struct {...} T;` case and therefore, isn't even able to handle a single declaration chain with braces in a template argument, such as `typedef S<T{ 0 < 0 }.b> S_t;`.

As to handling the comma cases:
(A) It is certainly not straightforward, since typedef declaration chains with multiple declarations are internally split up into separate declarations and the checker is called for each of these declarations individually.
(B) Your expansion would be valid, however, I think it might be easier to implement the expansion to

  using S_t = S<(0 < 0)>;
  using S_p = S<(0 < 0)>*;


Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67460/new/

https://reviews.llvm.org/D67460





More information about the cfe-commits mailing list