New issue
Advanced search Search tips

Issue 760094 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner: ----
Closed: Nov 26
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 2
Type: Bug

Blocked on:
issue 768586



Sign in to add a comment

clang-format: Wrong asterisk position in pointer variable declaration, within complex templates

Project Member Reported by yutak@chromium.org, Aug 29 2017

Issue description

I just saw "git cl format" formatted some Blink code in the following way:

    for (InT *value = value_begin; value != value_end; ++value, ++storage) {
             ^ SEE HERE

This is clearly wrong.

Full patch is here (see patch set 1):
https://chromium-review.googlesource.com/c/chromium/src/+/641290

Here, InT is a template type parameter of a function template in a class template
(so this is within double template<> nests), so there might be some bug related to
template handling.

This is a bit annoying to me, because I'm going to write a lot of templates
in the near future...
 

Comment 1 by yutak@chromium.org, Aug 30 2017

Cc: thakis@chromium.org
+Nico since this could be an issue in clang-format

Comment 2 by thakis@chromium.org, Aug 30 2017

Labels: clang-format
Huh, weird!

clang-format works on a token level, so the template nesting level shouldn't faze it much in theory. And indeed, this still happens if I remove all the template bits:

struct CopyRangeSupplement {
  static void CopyRange(const InT* value_begin,
                        const InT* value_end,
                        T* storage_begin) {
    T* storage = storage_begin;
    for (const InT *value = value_begin; value < value_end;
         ++value, ++storage) {
      TypeOperations::Assign(*storage, *value);
    }
  }
};

Simpler repro:

static void CopyRange() {
  foo* value;
  for (InT *value = value_begin; value < value_end; ++value, ++storage) {
  }
}

If I change the third part of the loop header to not contain a comma operator, it works. So I guess that's what confuses clang-format. But this is still pretty simple code, it's surprising this confuses it.

Comment 3 by thakis@chromium.org, Aug 30 2017

Still happens at trunk. Filed https://bugs.llvm.org/show_bug.cgi?id=34366
Fixed in upstream r34366. Rolling clang-format is a bit annoying to do -- if this is very important to you, we can do a roll. If it's of medium importance, I think it's time to finally build some infra to make clang-format rolls easier (this will take some time, but should hopefully be doable some time this year).

Comment 5 by yutak@chromium.org, Sep 4 2017

This is not so urgent, since I can reformat the code again when clang-format is
rolled.
Components: -Infra>SDK
Summary: clang-format: Wrong asterisk position in pointer variable declaration, within complex templates (was: git cl format: Wrong asterisk position in pointer variable declaration, within complex templates)

Comment 7 by thakis@chromium.org, Sep 25 2017

Blockedon: 768586
Components: Tools
Status: Fixed (was: Untriaged)
A clang-format with the fix got deployed on Nov 21 2018.

Sign in to add a comment