0

I think clang-format have some kind of problem with directive _Pragma("once") vs #pragma once - please see example below - namespaces indent changes depending on the pragma directive type used.

First way to use:

_Pragma("once")
#include <stdint.h>

#include "board/clock_config.h"
#include "board/pin_mux.h"
#include "fsl_uart.h"

    namespace wam {
  namespace board_1938 {

Second way:

#pragma once
#include <stdint.h>

#include "board/clock_config.h"
#include "board/pin_mux.h"
#include "fsl_uart.h"

namespace wam {
namespace board_1938 {
  • Neither `_Pragma("once")` nor `#pragma once` is valid standard C++. Use plain old header guards instead. – Jesper Juhl Aug 28 '20 at 14:54
  • Which version of clang-format is this? Have you tested on a newer version? – Botje Aug 28 '20 at 14:59
  • 3
    @JesperJuhl: We're talking about a format tool here, and that should be able to format all syntactically correct C++ code. While the meaning of `#pragma once` is implementation-defined, the Standard does prescribe the syntax. `_Pragma` is C++11, that's old enough that you'd expect support by now. – MSalters Aug 28 '20 at 15:11
  • Zack Weinberg rather strongly discourages the use of [`#pragma once`](https://stackoverflow.com/questions/1143936/pragma-once-vs-include-guards/34884735#34884735). He's the person who added it to GCC. – Eljay Aug 28 '20 at 16:04
  • @MSalters I said nothing in my comment about whether the tool should be able to deal with it or not. I purely commented on the fact that it's *not* standard C++ and advised to not use it - irrespective of what some formatting tool might do (or not do). – Jesper Juhl Aug 28 '20 at 16:17

0 Answers0