darwin added a comment.

In D97137#2577794 <https://reviews.llvm.org/D97137#2577794>, 
@HazardyKnusperkeks wrote:

> Just out of curiosity, in which language is `Const` used?

For example it is C's macro.

I found this issue in our C code. It has many macros and one function was 
defined like this:

  static IO_FLT_POSTOP_CALLBACK_STATUS FilterDriverClosePostOpCallback(
      IN OUT PIO_FLT_POSTOP_DATA          pPostopData,
      IN IO_FLT_RELATED_OBJECTS           FltObjects,
      IN OPTIONAL PIO_FLT_CONTEXT         pCompletionContext,
      IN IO_FLT_POST_OPERATION_FLAGS      Flags,
      OUT PIO_FLT_POSTOP_CANCEL_CALLBACK* pCancellationCallback,
      OUT OPTIONAL PVOID*                 ppCancellationContext)

And because of this issue, the last two lines couldn't be formatted properly:

  static IO_FLT_POSTOP_CALLBACK_STATUS FilterDriverClosePostOpCallback(
      IN OUT PIO_FLT_POSTOP_DATA     pPostopData,
      IN IO_FLT_RELATED_OBJECTS      FltObjects,
      IN OPTIONAL PIO_FLT_CONTEXT    pCompletionContext,
      IN IO_FLT_POST_OPERATION_FLAGS Flags,
      OUT PIO_FLT_POSTOP_CANCEL_CALLBACK* pCancellationCallback,
      OUT OPTIONAL PVOID* ppCancellationContext)

Then, I started to investigate this issue. Interestingly, if the token before 
the asterisk is a keyword like `const` or `int`, it works fine sometimes:

  static IO_FLT_POSTOP_CALLBACK_STATUS FilterDriverClosePostOpCallback(
      IN OUT PIO_FLT_POSTOP_DATA     pPostopData,
      IN IO_FLT_RELATED_OBJECTS      FltObjects,
      IN OPTIONAL PIO_FLT_CONTEXT    pCompletionContext,
      IN IO_FLT_POST_OPERATION_FLAGS Flags,
      OUT int*                       pCancellationCallback,                     
    <== I've changed PIO_FLT_POSTOP_CANCEL_CALLBACK into int, it could be 
formatted properly.
      OUT OPTIONAL const* ppCancellationContext)                                
    <== I've changed PVOID into const, it still couldn't be formatted properly.

I didn't know the reason behind of this. Anyway, after this modification, it 
can handle all these types of code.



================
Comment at: clang/unittests/Format/FormatTest.cpp:14257
+
+  Alignment.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("unsigned int*       a;\n"
----------------
curdeius wrote:
> Could you please test as well mixed pointers and references?
Sure.


================
Comment at: clang/unittests/Format/FormatTest.cpp:14260
+               "int*                b;\n"
+               "unsigned int Const* c;",
+               Alignment);
----------------
curdeius wrote:
> Could you please test `const` as well?
Sure.

Actually, clang-format worked well for `const` originally.


================
Comment at: clang/unittests/Format/FormatTest.cpp:14261
+               "unsigned int Const* c;",
+               Alignment);
 }
----------------
MyDeveloperDay wrote:
> can you test west const too?
> 
> ```
> Const unsigned int* c;
> const unsigned int* d;
> Const unsigned int& e;
> const unsigned int& f;
> const unsigned g;
> Const unsigned h;
> ```
> 
Sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97137

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

Reply via email to