Index: clang/lib/Parse/ParseStmt.cpp =================================================================== --- clang/lib/Parse/ParseStmt.cpp +++ clang/lib/Parse/ParseStmt.cpp @@ -220,6 +220,8 @@ Decl = ParseDeclaration(DeclaratorContext::BlockContext, DeclEnd, Attrs); } + if (Attrs.Range.getBegin().isValid()) + DeclStart = Attrs.Range.getBegin(); return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd); } Index: clang/test/AST/sourceranges.cpp =================================================================== --- clang/test/AST/sourceranges.cpp +++ clang/test/AST/sourceranges.cpp @@ -144,3 +144,18 @@ } } #endif + +// CHECK: NamespaceDecl {{.*}} attributed_decl +namespace attributed_decl { + void cpp11() { + // CHECK: DeclStmt {{.*}} + int __attribute__((unused)) i; + } + +#if __cplusplus >= 201703L + void cpp17() { + // CHECK-1Z: DeclStmt {{.*}} + [[maybe_unused]] int i; + } +#endif +}