llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.08k stars 11.09k forks source link

[clang-format] pragmas are considered hashes in IndentPPDirectives #97891

Closed zeule closed 4 days ago

zeule commented 2 weeks ago

When IndentPPDirectives is set to AfterHash, placing #pragma once at the beginning of the include file make all #include directives indented.

owenca commented 2 weeks ago

Please provide the version and config of clang-format and the code snippet you used.

zeule commented 2 weeks ago

Oops, sorry: llvm 18.1.8

.clang-format:

---
BasedOnStyle: LLVM
Language: Cpp
TabWidth: 4
UseTab: AlignWithSpaces
IndentWidth: 4

IndentPPDirectives: AfterHash

In a fragment:

#pragma once
#ifndef HEADER_ID_H
#define HEADER_ID_H // (1)

clang-format inserts indent in (1) after the hash sign

owenca commented 2 weeks ago

In a fragment:

#pragma once
#ifndef HEADER_ID_H
#define HEADER_ID_H // (1)

clang-format inserts indent in (1) after the hash sign

Doesn't the pragma make the header guard redundant and vice versa? Anyway, clang-format checks for header guards only at the beginning of the input as it's supposed to.