clang-format quality problem: badly formatted x-macros |
|||||
Issue description
clang-format produced code that (choose all that apply):
- Doesn't match Chromium style
- Doesn't match blink style
- Riles my finely honed stylistic dander
- No sane human would ever choose
Here's the code before formatting:
long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) {
DWORD exc_code = info->ExceptionRecord->ExceptionCode;
std::cerr << "Received fatal exception ";
switch (exc_code) {
#define EXC_CODE(x) \
case x: \
std::cerr << #x; \
break;
EXC_CODE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
EXC_CODE(EXCEPTION_BREAKPOINT)
EXC_CODE(EXCEPTION_DATATYPE_MISALIGNMENT)
EXC_CODE(EXCEPTION_FLT_DENORMAL_OPERAND)
EXC_CODE(EXCEPTION_FLT_DIVIDE_BY_ZERO)
EXC_CODE(EXCEPTION_FLT_INEXACT_RESULT)
EXC_CODE(EXCEPTION_FLT_INVALID_OPERATION)
EXC_CODE(EXCEPTION_FLT_OVERFLOW)
EXC_CODE(EXCEPTION_FLT_STACK_CHECK)
EXC_CODE(EXCEPTION_FLT_UNDERFLOW)
EXC_CODE(EXCEPTION_ILLEGAL_INSTRUCTION)
EXC_CODE(EXCEPTION_IN_PAGE_ERROR)
EXC_CODE(EXCEPTION_INT_DIVIDE_BY_ZERO)
EXC_CODE(EXCEPTION_INT_OVERFLOW)
EXC_CODE(EXCEPTION_INVALID_DISPOSITION)
EXC_CODE(EXCEPTION_NONCONTINUABLE_EXCEPTION)
EXC_CODE(EXCEPTION_PRIV_INSTRUCTION)
EXC_CODE(EXCEPTION_SINGLE_STEP)
EXC_CODE(EXCEPTION_STACK_OVERFLOW)
#undef EXC_CODE
default:
std::cerr << "0x" << std::hex << exc_code;
break;
}
std::cerr << "\n";
debug::StackTrace(info).Print();
if (g_previous_filter)
return g_previous_filter(info);
return EXCEPTION_CONTINUE_SEARCH;
}
Here's the code after formatting:
long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) {
DWORD exc_code = info->ExceptionRecord->ExceptionCode;
std::cerr << "Received fatal exception ";
switch (exc_code) {
#define EXC_CODE(x) \
case x : \
std::cerr << #x; \
break;
EXC_CODE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
EXC_CODE(EXCEPTION_BREAKPOINT)
EXC_CODE(EXCEPTION_DATATYPE_MISALIGNMENT)
EXC_CODE(EXCEPTION_FLT_DENORMAL_OPERAND)
EXC_CODE(EXCEPTION_FLT_DIVIDE_BY_ZERO)
EXC_CODE(EXCEPTION_FLT_INEXACT_RESULT)
EXC_CODE(EXCEPTION_FLT_INVALID_OPERATION)
EXC_CODE(EXCEPTION_FLT_OVERFLOW)
EXC_CODE(EXCEPTION_FLT_STACK_CHECK)
EXC_CODE(EXCEPTION_FLT_UNDERFLOW)
EXC_CODE(EXCEPTION_ILLEGAL_INSTRUCTION)
EXC_CODE(EXCEPTION_IN_PAGE_ERROR)
EXC_CODE(EXCEPTION_INT_DIVIDE_BY_ZERO)
EXC_CODE(EXCEPTION_INT_OVERFLOW)
EXC_CODE(EXCEPTION_INVALID_DISPOSITION)
EXC_CODE(EXCEPTION_NONCONTINUABLE_EXCEPTION)
EXC_CODE(EXCEPTION_PRIV_INSTRUCTION)
EXC_CODE(EXCEPTION_SINGLE_STEP)
EXC_CODE(EXCEPTION_STACK_OVERFLOW)
#undef EXC_CODE
default :
std::cerr << "0x" << std::hex << exc_code;
break;
}
std::cerr << "\n";
debug::StackTrace(info).Print();
if (g_previous_filter)
return g_previous_filter(info);
return EXCEPTION_CONTINUE_SEARCH;
}
Here's how it ought to look:
as original
Code review link for full files/context:
https://chromium-review.googlesource.com/c/chromium/src/+/714642
,
Oct 12 2017
,
Oct 12 2017
Do you also get that formatting if you copy the function into base/debug/stack_trace_win.cc? I can reproduce your result only if I create a standalone file with that function.
,
Oct 12 2017
Works there too. Maybe you have a different clang-format from chromium's on your PATH before depot_tools?
,
Oct 12 2017
There's a /usr/bin/clang-format on my path before chromium's, but I can also reproduce by invoking the clang-format in depot_tools, and by invoking buildtools/linux64/clang-format directly.
,
Oct 26 2017
,
Oct 29 2017
Jumping on to this issue since it's fairly recent and I've been irked by weird macro formatting issues with my X macros, but more generally for any multi-line macro.
Example:
#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
template<> \
struct ImplTypeHelper<gl::OBJ> \
{ \
using ImplType = OBJ##Vk; \
};
Result:
#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
\
template<> \
\
struct ImplTypeHelper<gl::OBJ> \
{ \
using ImplType = OBJ##Vk; \
\
};
Seems pretty weird that it got this confused.
,
Oct 30 2017
I can't repro that either. This is formatted like
#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
template <> \
struct ImplTypeHelper<gl::OBJ> { \
using ImplType = OBJ##Vk; \
};
on my system. If I put the code in a file in third_party/angle/src/libANGLE instead of in base/, it gets formatted like so:
#define ANGLE_IMPL_TYPE_HELPER_GL(OBJ) \
template <> \
struct ImplTypeHelper<gl::OBJ> \
{ \
using ImplType = OBJ##Vk; \
};
,
Nov 2 2017
OK, this is probably due to parsing of EOL differences on Windows CRLF files vs Unix LF files. It might be an easy fix for someone who is familiar with the code. Nico's away for a while, is there anyone who can offer some guidance?
,
Nov 2 2017
,
Jan 11
Issue has a component, but no priority. Updating to have default priority (Pri-2) |
|||||
►
Sign in to add a comment |
|||||
Comment 1 by thakis@chromium.org
, Oct 12 2017Formats it like so for me, which seems reasonable to me: long WINAPI StackDumpExceptionFilter(EXCEPTION_POINTERS* info) { DWORD exc_code = info->ExceptionRecord->ExceptionCode; std::cerr << "Received fatal exception "; switch (exc_code) { #define EXC_CODE(x) \ case x: \ std::cerr << #x; \ break; EXC_CODE(EXCEPTION_ARRAY_BOUNDS_EXCEEDED) EXC_CODE(EXCEPTION_BREAKPOINT) EXC_CODE(EXCEPTION_DATATYPE_MISALIGNMENT) EXC_CODE(EXCEPTION_FLT_DENORMAL_OPERAND) EXC_CODE(EXCEPTION_FLT_DIVIDE_BY_ZERO) EXC_CODE(EXCEPTION_FLT_INEXACT_RESULT) EXC_CODE(EXCEPTION_FLT_INVALID_OPERATION) EXC_CODE(EXCEPTION_FLT_OVERFLOW) EXC_CODE(EXCEPTION_FLT_STACK_CHECK) EXC_CODE(EXCEPTION_FLT_UNDERFLOW) EXC_CODE(EXCEPTION_ILLEGAL_INSTRUCTION) EXC_CODE(EXCEPTION_IN_PAGE_ERROR) EXC_CODE(EXCEPTION_INT_DIVIDE_BY_ZERO) EXC_CODE(EXCEPTION_INT_OVERFLOW) EXC_CODE(EXCEPTION_INVALID_DISPOSITION) EXC_CODE(EXCEPTION_NONCONTINUABLE_EXCEPTION) EXC_CODE(EXCEPTION_PRIV_INSTRUCTION) EXC_CODE(EXCEPTION_SINGLE_STEP) EXC_CODE(EXCEPTION_STACK_OVERFLOW) #undef EXC_CODE default: std::cerr << "0x" << std::hex << exc_code; break; } std::cerr << "\n"; debug::StackTrace(info).Print(); if (g_previous_filter) return g_previous_filter(info); return EXCEPTION_CONTINUE_SEARCH; } But worst-case, `//clang-format off` ... `//clang-format off`.