Lines Matching full:const
32 const FormatStyle &Style = getLLVMStyle()) {
41 EXPECT_EQ(LeftRightQualifierAlignmentFixer::getTokenFromQualifier("const"),
59 "QualifierOrder: [const, volatile, apples, type]",
61 std::vector<std::string>({"const", "volatile", "apples", "type"}));
68 "QualifierOrder: [const, volatile, const, type]",
70 std::vector<std::string>({"const", "volatile", "const", "type"}));
77 "QualifierOrder: [const, volatile ]",
80 "const",
103 std::vector<std::string>({"const", "volatile", "type"}));
110 std::vector<std::string>({"type", "const", "volatile"}));
117 "const", "volatile", "type"};
119 verifyFormat("const volatile int a;", Style);
120 verifyFormat("const volatile int a;", "volatile const int a;", Style);
121 verifyFormat("const volatile int a;", "int const volatile a;", Style);
122 verifyFormat("const volatile int a;", "int volatile const a;", Style);
123 verifyFormat("const volatile int a;", "const int volatile a;", Style);
125 verifyFormat("static const volatile int a;", "const static int volatile a;",
127 verifyFormat("inline static const volatile int a;",
128 "const static inline int volatile a;", Style);
135 verifyFormat("const const int a;", "const int const a;", Style);
138 "friend constexpr auto operator<=>(const foo &, const foo &) = default;",
139 "constexpr friend auto operator<=>(const foo &, const foo &) = default;",
142 "friend constexpr bool operator==(const foo &, const foo &) = default;",
143 "constexpr bool friend operator==(const foo &, const foo &) = default;",
150 // keep the const style unaltered
151 verifyFormat("const int a;", Style);
152 verifyFormat("const int *a;", Style);
153 verifyFormat("const int &a;", Style);
154 verifyFormat("const int &&a;", Style);
155 verifyFormat("int const b;", Style);
156 verifyFormat("int const *b;", Style);
157 verifyFormat("int const &b;", Style);
158 verifyFormat("int const &&b;", Style);
159 verifyFormat("int const *const b;", Style);
160 verifyFormat("int *const c;", Style);
162 verifyFormat("const Foo a;", Style);
163 verifyFormat("const Foo *a;", Style);
164 verifyFormat("const Foo &a;", Style);
165 verifyFormat("const Foo &&a;", Style);
166 verifyFormat("Foo const b;", Style);
167 verifyFormat("Foo const *b;", Style);
168 verifyFormat("Foo const &b;", Style);
169 verifyFormat("Foo const &&b;", Style);
170 verifyFormat("Foo const *const b;", Style);
172 verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
173 verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
175 verifyFormat("volatile const int *restrict;", Style);
176 verifyFormat("const volatile int *restrict;", Style);
177 verifyFormat("const int volatile *restrict;", Style);
183 Style.QualifierOrder = {"type", "const", "volatile"};
185 verifyFormat("int const a;", Style);
186 verifyFormat("int const *a;", Style);
187 verifyFormat("int const &a;", Style);
188 verifyFormat("int const &&a;", Style);
189 verifyFormat("int const b;", Style);
190 verifyFormat("int const *b;", Style);
191 verifyFormat("int const &b;", Style);
192 verifyFormat("int const &&b;", Style);
193 verifyFormat("int const *const b;", Style);
194 verifyFormat("int *const c;", Style);
196 verifyFormat("Foo const a;", Style);
197 verifyFormat("Foo const *a;", Style);
198 verifyFormat("Foo const &a;", Style);
199 verifyFormat("Foo const &&a;", Style);
200 verifyFormat("Foo const b;", Style);
201 verifyFormat("Foo const *b;", Style);
202 verifyFormat("Foo const &b;", Style);
203 verifyFormat("Foo const &&b;", Style);
204 verifyFormat("Foo const *const b;", Style);
205 verifyFormat("Foo *const b;", Style);
206 verifyFormat("Foo const *const b;", Style);
207 verifyFormat("auto const v = get_value();", Style);
208 verifyFormat("long long const &a;", Style);
209 verifyFormat("unsigned char const *a;", Style);
210 verifyFormat("int main(int const argc, char const *const *const argv)",
213 verifyFormat("LLVM_NODISCARD int const &Foo();", Style);
214 verifyFormat("SourceRange getSourceRange() const override LLVM_READONLY",
216 verifyFormat("void foo() const override;", Style);
217 verifyFormat("void foo() const override LLVM_READONLY;", Style);
218 verifyFormat("void foo() const final;", Style);
219 verifyFormat("void foo() const final LLVM_READONLY;", Style);
220 verifyFormat("void foo() const LLVM_READONLY;", Style);
221 verifyFormat("void foo() const volatile override;", Style);
222 verifyFormat("void foo() const volatile override LLVM_READONLY;", Style);
223 verifyFormat("void foo() const volatile final;", Style);
224 verifyFormat("void foo() const volatile final LLVM_READONLY;", Style);
225 verifyFormat("void foo() const volatile LLVM_READONLY;", Style);
228 "template <typename Func> explicit Action(Action<Func> const &action);",
231 "template <typename Func> explicit Action(Action<Func> const &action);",
232 "template <typename Func> explicit Action(const Action<Func>& action);",
235 "template <typename Func> explicit Action(Action<Func> const &action);",
236 "template <typename Func>\nexplicit Action(const Action<Func>& action);",
239 verifyFormat("int const a;", "const int a;", Style);
240 verifyFormat("int const *a;", "const int *a;", Style);
241 verifyFormat("int const &a;", "const int &a;", Style);
242 verifyFormat("foo(int const &a)", "foo(const int &a)", Style);
244 verifyFormat("unsigned char const *a;", "const unsigned char *a;", Style);
245 verifyFormat("vector<int, int const, int &, int const &> args1",
246 "vector<int, const int, int &, const int &> args1", Style);
247 verifyFormat("unsigned int const &get_nu() const",
248 "const unsigned int &get_nu() const", Style);
249 verifyFormat("Foo<int> const &a", "const Foo<int> &a", Style);
250 verifyFormat("Foo<int>::iterator const &a", "const Foo<int>::iterator &a",
252 verifyFormat("::Foo<int>::iterator const &a", "const ::Foo<int>::iterator &a",
257 " Bar const &c);",
260 " const Bar &c);",
263 verifyFormat("int const volatile;", "volatile const int;", Style);
264 verifyFormat("int const volatile;", "const volatile int;", Style);
265 verifyFormat("int const volatile;", "const int volatile;", Style);
267 verifyFormat("int const volatile *restrict;", "volatile const int *restrict;",
269 verifyFormat("int const volatile *restrict;", "const volatile int *restrict;",
271 verifyFormat("int const volatile *restrict;", "const int volatile *restrict;",
274 verifyFormat("long long int const volatile;", "const long long int volatile;",
276 verifyFormat("long long int const volatile;", "long const long int volatile;",
278 verifyFormat("long long int const volatile;", "long long volatile int const;",
280 verifyFormat("long long int const volatile;", "long volatile long const int;",
282 verifyFormat("long long int const volatile;", "const long long volatile int;",
285 verifyFormat("static int const bat;", "static const int bat;", Style);
286 verifyFormat("static int const bat;", Style);
290 verifyFormat("int static const volatile;", "volatile const int static;",
292 verifyFormat("int static const volatile;", "const volatile int static;",
294 verifyFormat("int static const volatile;", "const int volatile static;",
296 verifyFormat("Foo static const volatile;", "volatile const Foo static;",
298 verifyFormat("Foo static const volatile;", "const volatile Foo static;",
300 verifyFormat("Foo static const volatile;", "const Foo volatile static;",
303 verifyFormat("Foo inline static const;", "const Foo inline static;", Style);
304 verifyFormat("Foo inline static const;", "Foo const inline static;", Style);
305 verifyFormat("Foo inline static const;", "Foo inline const static;", Style);
306 verifyFormat("Foo inline static const;", Style);
308 verifyFormat("Foo<T volatile>::Bar<Type const, 5> const volatile A::*;",
309 "volatile const Foo<volatile T>::Bar<const Type, 5> A::*;",
312 verifyFormat("int const Foo<int>::bat = 0;", "const int Foo<int>::bat = 0;",
314 verifyFormat("int const Foo<int>::bat = 0;", Style);
315 verifyFormat("void fn(Foo<T> const &i);", "void fn(const Foo<T> &i);", Style);
316 verifyFormat("int const Foo<int>::fn() {", Style);
317 verifyFormat("Foo<Foo<int>> const *p;", "const Foo<Foo<int>> *p;", Style);
319 "Foo<Foo<int>> const *p = const_cast<Foo<Foo<int>> const *>(&ffi);",
320 "const Foo<Foo<int>> *p = const_cast<const Foo<Foo<int>> *>(&ffi);",
323 verifyFormat("void fn(Foo<T> const &i);", "void fn(const Foo<T> &i);", Style);
324 verifyFormat("void fns(ns::S const &s);", "void fns(const ns::S &s);", Style);
325 verifyFormat("void fns(::ns::S const &s);", "void fns(const ::ns::S &s);",
327 verifyFormat("void fn(ns::Foo<T> const &i);", "void fn(const ns::Foo<T> &i);",
329 verifyFormat("void fns(ns::ns2::S const &s);",
330 "void fns(const ns::ns2::S &s);", Style);
331 verifyFormat("void fn(ns::Foo<Bar<T>> const &i);",
332 "void fn(const ns::Foo<Bar<T>> &i);", Style);
333 verifyFormat("void fn(ns::ns2::Foo<Bar<T>> const &i);",
334 "void fn(const ns::ns2::Foo<Bar<T>> &i);", Style);
335 verifyFormat("void fn(ns::ns2::Foo<Bar<T, U>> const &i);",
336 "void fn(const ns::ns2::Foo<Bar<T, U>> &i);", Style);
338 verifyFormat("LocalScope const *Scope = nullptr;",
339 "const LocalScope* Scope = nullptr;", Style);
340 verifyFormat("struct DOTGraphTraits<Stmt const *>",
341 "struct DOTGraphTraits<const Stmt *>", Style);
344 "bool tools::addXRayRuntime(ToolChain const &TC, ArgList const &Args) {",
345 "bool tools::addXRayRuntime(const ToolChain&TC, const ArgList &Args) {",
347 verifyFormat("Foo<Foo<int> const> P;", "Foo<const Foo<int>> P;", Style);
348 verifyFormat("Foo<Foo<int> const> P;\n#if 0\n#else\n#endif",
349 "Foo<const Foo<int>> P;\n#if 0\n#else\n#endif", Style);
351 verifyFormat("auto const i = 0;", "const auto i = 0;", Style);
352 verifyFormat("auto const &ir = i;", "const auto &ir = i;", Style);
353 verifyFormat("auto const *ip = &i;", "const auto *ip = &i;", Style);
355 verifyFormat("void f(Concept auto const &x);",
356 "void f(const Concept auto &x);", Style);
357 verifyFormat("void f(std::integral auto const &x);",
358 "void f(const std::integral auto &x);", Style);
360 verifyFormat("auto lambda = [] { int const i = 0; };",
361 "auto lambda = [] { const int i = 0; };", Style);
363 verifyFormat("Foo<Foo<int> const> P;\n#if 0\n#else\n#endif",
364 "Foo<const Foo<int>> P;\n#if 0\n#else\n#endif", Style);
366 verifyFormat("Bar<Bar<int const> const> P;\n#if 0\n#else\n#endif",
367 "Bar<Bar<const int> const> P;\n#if 0\n#else\n#endif", Style);
369 verifyFormat("Baz<Baz<int const> const> P;\n#if 0\n#else\n#endif",
370 "Baz<const Baz<const int>> P;\n#if 0\n#else\n#endif", Style);
372 // verifyFormat("#if 0\nBoo<Boo<int const> const> P;\n#else\n#endif",
373 // "#if 0\nBoo<const Boo<const int>> P;\n#else\n#endif", Style);
375 verifyFormat("int const P;\n#if 0\n#else\n#endif",
376 "const int P;\n#if 0\n#else\n#endif", Style);
378 verifyFormat("unsigned long const a;", "const unsigned long a;", Style);
379 verifyFormat("unsigned long long const a;", "const unsigned long long a;",
383 verifyFormat("Bar<std::Foo const, 32>", "Bar<const std::Foo, 32>", Style);
385 verifyFormat("Bar<std::Foo const> bar", "Bar<const std::Foo> bar", Style);
388 verifyFormat("typename Foo::iterator const;", "const typename Foo::iterator;",
392 verifyFormat("void foo(const struct A a);", Style);
393 verifyFormat("void foo(const class A a);", Style);
397 verifyFormat("const struct {\n} var;", Style);
398 verifyFormat("struct {\n} const var;", Style);
399 verifyFormat("const class {\n} var;", Style);
400 verifyFormat("class {\n} const var;", Style);
404 verifyFormat("volatile const class {\n} var;", Style);
405 verifyFormat("const volatile class {\n} var;", Style);
407 verifyFormat("const static volatile class {\n} var;", Style);
409 verifyFormat("class {\n} const volatile var;", Style);
410 verifyFormat("class {\n} const volatile var;",
411 "class {\n} volatile const var;", Style);
414 verifyFormat("class {\n} static const volatile var;", Style);
415 verifyFormat("class {\n} static const volatile var;",
416 "class {\n} volatile static const var;", Style);
419 verifyFormat("::template Foo<T> const volatile var;",
420 "const volatile ::template Foo<T> var;", Style);
421 verifyFormat("typename ::template Foo<T> const volatile var;",
422 "const volatile typename ::template Foo<T> var;", Style);
423 verifyFormat("typename Bar::template Foo<T>::T const;",
424 "const typename Bar::template Foo<T>::T;", Style);
425 verifyFormat("typename Bar::template Foo<T>::T const volatile;",
426 "const volatile typename Bar::template Foo<T>::T;", Style);
429 verifyFormat("typename ::Bar<int> const;", "const typename ::Bar<int>;",
432 verifyFormat("typename ::template Bar<int> const;",
433 "const typename ::template Bar<int>;", Style);
435 verifyFormat("foo<Bar<Baz> const>();", "foo<const Bar<Baz>>();", Style);
436 verifyFormat("foo<Bar<Baz> const>();", "foo<const Bar<Baz> >();", Style);
437 verifyFormat("Bar<32, Foo<25> const>;", "Bar<32, const Foo<25>>;", Style);
438 verifyFormat("A<B<C<D> const> const>;", "A<const B<const C<D>>>;", Style);
439 verifyFormat("A<B<C<D const> const> const>;", "A<const B<const C<const D>>>;",
443 verifyFormat("const decltype(foo)", Style);
444 verifyFormat("const typeof(foo)", Style);
445 verifyFormat("const _Atomic(foo)", Style);
448 const int ColumnLimit = Style.ColumnLimit;
450 verifyFormat("/*c*/ Foo const *foo;", "const /*c*/ Foo *foo;", Style);
451 verifyFormat("Foo const /*c*/ *foo;", "const Foo /*c*/ *foo;", Style);
452 verifyFormat("Foo const * /*c*/ foo;", "const Foo * /*c*/ foo;", Style);
454 verifyFormat("/*comment*/ std::vector<int> const v;",
455 "const /*comment*/ std::vector<int> v;", Style);
456 verifyFormat("std /*comment*/ ::vector<int> const v;",
457 "const std /*comment*/ ::vector<int> v;", Style);
458 verifyFormat("std::/*comment*/ vector<int> const v;",
459 "const std::/*comment*/ vector<int> v;", Style);
460 verifyFormat("std::vector /*comment*/<int> const v;",
461 "const std::vector /*comment*/ <int> v;", Style);
462 verifyFormat("std::vector</*comment*/ int> const v;",
463 "const std::vector</*comment*/ int> v;", Style);
464 verifyFormat("std::vector<int /*comment*/> const v;",
465 "const std::vector<int /*comment*/> v;", Style);
466 verifyFormat("std::vector<int> const /*comment*/ v;",
467 "const std::vector<int> /*comment*/ v;", Style);
469 verifyFormat("std::vector</*comment*/ int const> v;",
470 "std::vector</*comment*/ const int> v;", Style);
471 verifyFormat("std::vector</*comment*/ int const> v;",
472 "std::vector<const /*comment*/ int> v;", Style);
473 verifyFormat("std::vector<int const /*comment*/> v;",
474 "std::vector<const int /*comment*/> v;", Style);
475 verifyFormat("std::vector</*comment*/ Foo const> v;",
476 "std::vector</*comment*/ const Foo> v;", Style);
477 verifyFormat("std::vector</*comment*/ Foo const> v;",
478 "std::vector<const /*comment*/ Foo> v;", Style);
479 verifyFormat("std::vector<Foo const /*comment*/> v;",
480 "std::vector<const Foo /*comment*/> v;", Style);
482 verifyFormat("typename C<T>::template B<T> const;",
483 "const typename C<T>::template B<T>;", Style);
484 verifyFormat("/*c*/ typename C<T>::template B<T> const;",
485 "const /*c*/ typename C<T>::template B<T>;", Style);
486 verifyFormat("typename /*c*/ C<T>::template B<T> const;",
487 "const typename /*c*/ C<T>::template B<T>;", Style);
488 verifyFormat("typename C /*c*/<T>::template B<T> const;",
489 "const typename C /*c*/<T>::template B<T>;", Style);
490 verifyFormat("typename C<T> /*c*/ ::template B<T> const;",
491 "const typename C<T> /*c*/ ::template B<T>;", Style);
492 verifyFormat("typename C<T>::/*c*/ template B<T> const;",
493 "const typename C<T>::/*c*/ template B<T>;", Style);
494 verifyFormat("typename C<T>::template /*c*/ B<T> const;",
495 "const typename C<T>::template /*c*/B<T>;", Style);
496 verifyFormat("typename C<T>::template B<T> const /*c*/;",
497 "const typename C<T>::template B<T>/*c*/;", Style);
500 "/*c*/ B /*c*/<T> const /*c*/ v;",
501 "/*c*/ const /*c*/ typename /*c*/ C /*c*/<T> /*c*/ "
505 verifyFormat("/*c*/ unsigned /*c*/ long const /*c*/ a;",
506 "const /*c*/ unsigned /*c*/ long /*c*/ a;", Style);
507 verifyFormat("unsigned /*c*/ long /*c*/ long const a;",
508 "const unsigned /*c*/ long /*c*/ long a;", Style);
511 verifyFormat("foo() /*c*/ const", Style);
512 verifyFormat("const /*c*/ struct a;", Style);
513 verifyFormat("const /*c*/ class a;", Style);
514 verifyFormat("const /*c*/ decltype(v) a;", Style);
515 verifyFormat("const /*c*/ typeof(v) a;", Style);
516 verifyFormat("const /*c*/ _Atomic(v) a;", Style);
517 verifyFormat("const decltype /*c*/ (v) a;", Style);
518 verifyFormat("const /*c*/ class {\n} volatile /*c*/ foo = {};", Style);
523 verifyFormat("const INTPTR a;", Style);
527 verifyFormat("int const S::*a;", "const int S::*a;", Style);
528 verifyFormat("int const S::*const a;", "const int S::* const a;", Style);
529 verifyFormat("int A::*const A::*p1;", Style);
531 verifyFormat("float (C::*const p)(int);", Style);
532 verifyFormat("float (C::*p)(int) const;", Style);
533 verifyFormat("float const (C::*p)(int);", "const float (C::*p)(int);", Style);
537 verifyFormat("auto foo() -> T const { return bar; }",
538 "auto foo() -> const T { return bar; }", Style);
544 Style.QualifierOrder = {"inline", "static", "const", "volatile", "type"};
546 verifyFormat("const int a;", Style);
547 verifyFormat("const int *a;", Style);
548 verifyFormat("const int &a;", Style);
549 verifyFormat("const int &&a;", Style);
550 verifyFormat("const int b;", Style);
551 verifyFormat("const int *b;", Style);
552 verifyFormat("const int &b;", Style);
553 verifyFormat("const int &&b;", Style);
554 verifyFormat("const int *const b;", Style);
555 verifyFormat("int *const c;", Style);
557 verifyFormat("const Foo a;", Style);
558 verifyFormat("const Foo *a;", Style);
559 verifyFormat("const Foo &a;", Style);
560 verifyFormat("const Foo &&a;", Style);
561 verifyFormat("const Foo b;", Style);
562 verifyFormat("const Foo *b;", Style);
563 verifyFormat("const Foo &b;", Style);
564 verifyFormat("const Foo &&b;", Style);
565 verifyFormat("const Foo *const b;", Style);
566 verifyFormat("Foo *const b;", Style);
567 verifyFormat("const Foo *const b;", Style);
569 verifyFormat("LLVM_NODISCARD const int &Foo();", Style);
571 verifyFormat("const char a[];", Style);
572 verifyFormat("const auto v = get_value();", Style);
573 verifyFormat("const long long &a;", Style);
574 verifyFormat("const unsigned char *a;", Style);
575 verifyFormat("const unsigned char *a;", "unsigned char const *a;", Style);
576 verifyFormat("const Foo<int> &a", "Foo<int> const &a", Style);
577 verifyFormat("const Foo<int>::iterator &a", "Foo<int>::iterator const &a",
579 verifyFormat("const ::Foo<int>::iterator &a", "::Foo<int>::iterator const &a",
582 verifyFormat("const int a;", "int const a;", Style);
583 verifyFormat("const int *a;", "int const *a;", Style);
584 verifyFormat("const int &a;", "int const &a;", Style);
585 verifyFormat("foo(const int &a)", "foo(int const &a)", Style);
587 verifyFormat("const unsigned int &get_nu() const",
588 "unsigned int const &get_nu() const", Style);
590 verifyFormat("const volatile int;", "volatile const int;", Style);
591 verifyFormat("const volatile int;", Style);
592 verifyFormat("const volatile int;", "const int volatile;", Style);
594 verifyFormat("const volatile int *restrict;", "volatile const int *restrict;",
596 verifyFormat("const volatile int *restrict;", Style);
597 verifyFormat("const volatile int *restrict;", "const int volatile *restrict;",
600 verifyFormat("const volatile long long int;", "volatile long long int const;",
602 verifyFormat("const volatile long long int;", "volatile long long const int;",
604 verifyFormat("const volatile long long int;", "long long volatile int const;",
606 verifyFormat("const volatile long long int;", "long volatile long int const;",
608 verifyFormat("const volatile long long int;", "const long long volatile int;",
611 verifyFormat("SourceRange getSourceRange() const override LLVM_READONLY;",
614 verifyFormat("void foo() const override;", Style);
615 verifyFormat("void foo() const override LLVM_READONLY;", Style);
616 verifyFormat("void foo() const final;", Style);
617 verifyFormat("void foo() const final LLVM_READONLY;", Style);
618 verifyFormat("void foo() const LLVM_READONLY;", Style);
621 "template <typename Func> explicit Action(const Action<Func> &action);",
624 "template <typename Func> explicit Action(const Action<Func> &action);",
625 "template <typename Func> explicit Action(Action<Func> const &action);",
628 verifyFormat("static const int bat;", Style);
629 verifyFormat("static const int bat;", "static int const bat;", Style);
631 verifyFormat("static const int Foo<int>::bat = 0;", Style);
632 verifyFormat("static const int Foo<int>::bat = 0;",
633 "static int const Foo<int>::bat = 0;", Style);
635 verifyFormat("void fn(const Foo<T> &i);");
637 verifyFormat("const int Foo<int>::bat = 0;", Style);
638 verifyFormat("const int Foo<int>::bat = 0;", "int const Foo<int>::bat = 0;",
640 verifyFormat("void fn(const Foo<T> &i);", "void fn( Foo<T> const &i);",
642 verifyFormat("const int Foo<int>::fn() {", "int const Foo<int>::fn() {",
644 verifyFormat("const Foo<Foo<int>> *p;", "Foo<Foo<int>> const *p;", Style);
646 "const Foo<Foo<int>> *p = const_cast<const Foo<Foo<int>> *>(&ffi);",
647 "const Foo<Foo<int>> *p = const_cast<Foo<Foo<int>> const *>(&ffi);",
650 verifyFormat("void fn(const Foo<T> &i);", "void fn(Foo<T> const &i);", Style);
651 verifyFormat("void fns(const ns::S &s);", "void fns(ns::S const &s);", Style);
652 verifyFormat("void fns(const ::ns::S &s);", "void fns(::ns::S const &s);",
654 verifyFormat("void fn(const ns::Foo<T> &i);", "void fn(ns::Foo<T> const &i);",
656 verifyFormat("void fns(const ns::ns2::S &s);",
657 "void fns(ns::ns2::S const &s);", Style);
658 verifyFormat("void fn(const ns::Foo<Bar<T>> &i);",
659 "void fn(ns::Foo<Bar<T>> const &i);", Style);
660 verifyFormat("void fn(const ns::ns2::Foo<Bar<T>> &i);",
661 "void fn(ns::ns2::Foo<Bar<T>> const &i);", Style);
662 verifyFormat("void fn(const ns::ns2::Foo<Bar<T, U>> &i);",
663 "void fn(ns::ns2::Foo<Bar<T, U>> const &i);", Style);
665 verifyFormat("const auto i = 0;", "auto const i = 0;", Style);
666 verifyFormat("const auto &ir = i;", "auto const &ir = i;", Style);
667 verifyFormat("const auto *ip = &i;", "auto const *ip = &i;", Style);
669 verifyFormat("void f(const Concept auto &x);",
670 "void f(Concept auto const &x);", Style);
671 verifyFormat("void f(const std::integral auto &x);",
672 "void f(std::integral auto const &x);", Style);
674 verifyFormat("auto lambda = [] { const int i = 0; };",
675 "auto lambda = [] { int const i = 0; };", Style);
677 verifyFormat("Foo<const Foo<int>> P;\n#if 0\n#else\n#endif",
678 "Foo<Foo<int> const> P;\n#if 0\n#else\n#endif", Style);
680 verifyFormat("Foo<Foo<const int>> P;\n#if 0\n#else\n#endif",
681 "Foo<Foo<int const>> P;\n#if 0\n#else\n#endif", Style);
683 verifyFormat("const int P;\n#if 0\n#else\n#endif",
684 "int const P;\n#if 0\n#else\n#endif", Style);
686 verifyFormat("const unsigned long a;", "unsigned long const a;", Style);
687 verifyFormat("const unsigned long long a;", "unsigned long long const a;",
690 verifyFormat("const long long unsigned a;", "long const long unsigned a;",
693 verifyFormat("const std::Foo", Style);
694 verifyFormat("const std::Foo<>", Style);
695 verifyFormat("const std::Foo < int", "const std::Foo<int", Style);
696 verifyFormat("const std::Foo<int>", Style);
699 verifyFormat("Bar<const std::Foo, 32>;", "Bar<std::Foo const, 32>;", Style);
702 verifyFormat("Bar<const std::Foo> bar;", "Bar<std::Foo const> bar;", Style);
705 verifyFormat("const typename Foo::iterator;", "typename Foo::iterator const;",
709 verifyFormat("void foo(struct A const a);", Style);
710 verifyFormat("void foo(class A const a);", Style);
714 verifyFormat("const struct {\n} var;", Style);
715 verifyFormat("struct {\n} const var;", Style);
716 verifyFormat("const class {\n} var;", Style);
717 verifyFormat("class {\n} const var;", Style);
721 verifyFormat("const volatile class {\n} var;", Style);
722 verifyFormat("const volatile class {\n} var;",
723 "volatile const class {\n} var;", Style);
726 verifyFormat("class {\n} const volatile var;", Style);
727 verifyFormat("class {\n} volatile const var;", Style);
729 verifyFormat("foo<const Bar<Baz<T>>>();", "foo<Bar<Baz<T>> const>();", Style);
730 verifyFormat("foo<const Bar<Baz<T>>>();", "foo<Bar<Baz<T> > const>();",
732 verifyFormat("Bar<32, const Foo<25>>;", "Bar<32, Foo<25> const>;", Style);
733 verifyFormat("A<const B<const C<D>>>;", "A<B<C<D> const> const>;", Style);
734 verifyFormat("A<const B<const C<const D>>>;", "A<B<C<D const> const> const>;",
738 verifyFormat("decltype(foo) const", Style);
739 verifyFormat("typeof(foo) const", Style);
740 verifyFormat("_Atomic(foo) const", Style);
743 verifyFormat("const volatile ::template Foo<T> var;",
744 "::template Foo<T> const volatile var;", Style);
745 verifyFormat("const volatile typename ::template Foo<T> var;",
746 "typename ::template Foo<T> const volatile var;", Style);
747 verifyFormat("const typename Bar::template Foo<T>::T;",
748 "typename Bar::template Foo<T>::T const;", Style);
749 verifyFormat("const volatile typename Bar::template Foo<T>::T;",
750 "typename Bar::template Foo<T>::T const volatile;", Style);
753 verifyFormat("const typename ::Bar<int>;", "typename ::Bar<int> const;",
756 verifyFormat("const typename ::template Bar<int>;",
757 "typename ::template Bar<int> const;", Style);
760 const int ColumnLimit = Style.ColumnLimit;
762 verifyFormat("/*c*/ const Foo *foo;", "/*c*/ Foo const *foo;", Style);
763 verifyFormat("const Foo /*c*/ *foo;", "Foo const /*c*/ *foo;", Style);
764 verifyFormat("const Foo * /*c*/ foo;", "Foo const * /*c*/ foo;", Style);
766 verifyFormat("/*comment*/ const std::vector<int> v;",
767 "/*comment*/ std::vector<int> const v;", Style);
768 verifyFormat("const std /*comment*/ ::vector<int> v;",
769 "std /*comment*/ ::vector<int> const v;", Style);
770 verifyFormat("const std::/*comment*/ vector<int> v;",
771 "std::/*comment*/ vector<int> const v;", Style);
772 verifyFormat("const std::vector /*comment*/<int> v;",
773 "std::vector /*comment*/<int> const v;", Style);
774 verifyFormat("const std::vector</*comment*/ int> v;",
775 "std::vector</*comment*/ int> const v;", Style);
776 verifyFormat("const std::vector<int /*comment*/> v;",
777 "std::vector<int /*comment*/> const v;", Style);
778 verifyFormat("const std::vector<int> /*comment*/ v;",
779 "std::vector<int> /*comment*/ const v;", Style);
781 verifyFormat("std::vector</*comment*/ const int> v;",
782 "std::vector</*comment*/ int const> v;", Style);
783 verifyFormat("std::vector<const int /*comment*/> v;",
784 "std::vector<int /*comment*/ const> v;", Style);
785 verifyFormat("std::vector<const int /*comment*/> v;",
786 "std::vector<int const /*comment*/> v;", Style);
787 verifyFormat("std::vector</*comment*/ const Foo> v;",
788 "std::vector</*comment*/ Foo const> v;", Style);
789 verifyFormat("std::vector<const Foo /*comment*/> v;",
790 "std::vector<Foo /*comment*/ const> v;", Style);
791 verifyFormat("std::vector<const Foo /*comment*/> v;",
792 "std::vector<Foo const /*comment*/> v;", Style);
794 verifyFormat("const typename C<T>::template B<T>;",
795 "typename C<T>::template B<T> const;", Style);
796 verifyFormat("/*c*/ const typename C<T>::template B<T>;",
797 "/*c*/ typename C<T>::template B<T> const;", Style);
798 verifyFormat("const typename /*c*/ C<T>::template B<T>;",
799 "typename /*c*/ C<T>::template B<T> const;", Style);
800 verifyFormat("const typename C /*c*/<T>::template B<T>;",
801 "typename C /*c*/<T>::template B<T> const;", Style);
802 verifyFormat("const typename C<T> /*c*/ ::template B<T>;",
803 "typename C<T> /*c*/ ::template B<T> const;", Style);
804 verifyFormat("const typename C<T>::/*c*/ template B<T>;",
805 "typename C<T>::/*c*/ template B<T> const;", Style);
806 verifyFormat("const typename C<T>::template /*c*/ B<T>;",
807 "typename C<T>::template /*c*/ B<T> const;", Style);
808 verifyFormat("const typename C<T>::template B<T> /*c*/;",
809 "typename C<T>::template B<T> /*c*/ const;", Style);
811 verifyFormat("/*c*/ const typename /*c*/ C /*c*/<T> /*c*/ ::/*c*/ template "
814 "/*c*/<T> /*c*/ const v;",
817 verifyFormat("const unsigned /*c*/ long /*c*/ a;",
818 "unsigned /*c*/ long /*c*/ const a;", Style);
819 verifyFormat("const unsigned /*c*/ long /*c*/ long a;",
820 "unsigned /*c*/ long /*c*/ long const a;", Style);
823 verifyFormat("foo() /*c*/ const", Style);
824 verifyFormat("struct /*c*/ const a;", Style);
825 verifyFormat("class /*c*/ const a;", Style);
826 verifyFormat("decltype(v) /*c*/ const a;", Style);
827 verifyFormat("typeof(v) /*c*/ const a;", Style);
828 verifyFormat("_Atomic(v) /*c*/ const a;", Style);
829 verifyFormat("decltype /*c*/ (v) const a;", Style);
830 verifyFormat("const /*c*/ class {\n} /*c*/ volatile /*c*/ foo = {};", Style);
835 verifyFormat("INTPTR const a;", Style);
839 verifyFormat("const int S::*a;", "int const S::*a;", Style);
840 verifyFormat("const int S::*const a;", "int const S::*const a;", Style);
841 verifyFormat("int A::*const A::*p1;", Style);
843 verifyFormat("float (C::*const p)(int);", Style);
844 verifyFormat("float (C::*p)(int) const;", Style);
845 verifyFormat("const float (C::*p)(int);", "float const (C::*p)(int);", Style);
851 Style.QualifierOrder = {"inline", "static", "const", "volatile", "type"};
856 verifyFormat("const volatile int a;", Style);
857 verifyFormat("const volatile int a;", "volatile const int a;", Style);
858 verifyFormat("const volatile int a;", "int const volatile a;", Style);
859 verifyFormat("const volatile int a;", "int volatile const a;", Style);
860 verifyFormat("const volatile int a;", "const int volatile a;", Style);
862 verifyFormat("const volatile Foo a;", Style);
863 verifyFormat("const volatile Foo a;", "volatile const Foo a;", Style);
864 verifyFormat("const volatile Foo a;", "Foo const volatile a;", Style);
865 verifyFormat("const volatile Foo a;", "Foo volatile const a;", Style);
866 verifyFormat("const volatile Foo a;", "const Foo volatile a;", Style);
869 Style.QualifierOrder = {"type", "const", "volatile"};
871 verifyFormat("int const volatile a;", "const volatile int a;", Style);
872 verifyFormat("int const volatile a;", "volatile const int a;", Style);
873 verifyFormat("int const volatile a;", Style);
874 verifyFormat("int const volatile a;", "int volatile const a;", Style);
875 verifyFormat("int const volatile a;", "const int volatile a;", Style);
877 verifyFormat("Foo const volatile a;", "const volatile Foo a;", Style);
878 verifyFormat("Foo const volatile a;", "volatile const Foo a;", Style);
879 verifyFormat("Foo const volatile a;", Style);
880 verifyFormat("Foo const volatile a;", "Foo volatile const a;", Style);
881 verifyFormat("Foo const volatile a;", "const Foo volatile a;", Style);
884 Style.QualifierOrder = {"volatile", "const", "type"};
886 verifyFormat("volatile const int a;", "const volatile int a;", Style);
887 verifyFormat("volatile const int a;", Style);
888 verifyFormat("volatile const int a;", "int const volatile a;", Style);
889 verifyFormat("volatile const int a;", "int volatile const a;", Style);
890 verifyFormat("volatile const int a;", "const int volatile a;", Style);
892 verifyFormat("volatile const Foo a;", "const volatile Foo a;", Style);
893 verifyFormat("volatile const Foo a;", Style);
894 verifyFormat("volatile const Foo a;", "Foo const volatile a;", Style);
895 verifyFormat("volatile const Foo a;", "Foo volatile const a;", Style);
896 verifyFormat("volatile const Foo a;", "const Foo volatile a;", Style);
899 Style.QualifierOrder = {"type", "volatile", "const"};
901 verifyFormat("int volatile const a;", "const volatile int a;", Style);
902 verifyFormat("int volatile const a;", "volatile const int a;", Style);
903 verifyFormat("int volatile const a;", "int const volatile a;", Style);
904 verifyFormat("int volatile const a;", Style);
905 verifyFormat("int volatile const a;", "const int volatile a;", Style);
907 verifyFormat("Foo volatile const a;", "const volatile Foo a;", Style);
908 verifyFormat("Foo volatile const a;", "volatile const Foo a;", Style);
909 verifyFormat("Foo volatile const a;", "Foo const volatile a;", Style);
910 verifyFormat("Foo volatile const a;", Style);
911 verifyFormat("Foo volatile const a;", "const Foo volatile a;", Style);
914 Style.QualifierOrder = {"type", "volatile", "const"};
916 verifyFormat("int volatile const a;", "const volatile int a;", Style);
917 verifyFormat("int volatile const a;", "volatile const int a;", Style);
918 verifyFormat("int volatile const a;", "int const volatile a;", Style);
919 verifyFormat("int volatile const a;", Style);
920 verifyFormat("int volatile const a;", "const int volatile a;", Style);
922 verifyFormat("Foo volatile const a;", "const volatile Foo a;", Style);
923 verifyFormat("Foo volatile const a;", "volatile const Foo a;", Style);
924 verifyFormat("Foo volatile const a;", "Foo const volatile a;", Style);
925 verifyFormat("Foo volatile const a;", Style);
926 verifyFormat("Foo volatile const a;", "const Foo volatile a;", Style);
932 Style.QualifierOrder = {"inline", "static", "const", "volatile", "type"};
935 verifyFormat("inline static const volatile int a;",
936 "const inline static volatile int a;", Style);
937 verifyFormat("inline static const volatile int a;",
938 "volatile inline static const int a;", Style);
939 verifyFormat("inline static const volatile int a;",
940 "int const inline static volatile a;", Style);
941 verifyFormat("inline static const volatile int a;",
942 "int volatile inline static const a;", Style);
943 verifyFormat("inline static const volatile int a;",
944 "const int inline static volatile a;", Style);
950 Style.QualifierOrder = {"static", "type", "const"};
953 verifyFormat("foo(std::string const & = std::string()) const",
954 "foo(const std::string & = std::string()) const", Style);
955 verifyFormat("foo(std::string const & = std::string())",
956 "foo(const std::string & = std::string())", Style);
963 Style.QualifierOrder = {"type", "const"};
966 verifyFormat("int const a;", "const int a;", Style);
967 verifyFormat("int const *a;", "const int*a;", Style);
968 verifyFormat("int const *a;", "const int *a;", Style);
969 verifyFormat("int const &a;", "const int &a;", Style);
970 verifyFormat("int const &&a;", "const int &&a;", Style);
977 Style.QualifierOrder = {"const", "type"};
980 verifyFormat("const int a;", "int const a;", Style);
981 verifyFormat("const int *a;", "int const *a;", Style);
982 verifyFormat("const int *const a;", "int const *const a;", Style);
984 verifyFormat("const int a = foo();", "int const a = foo();", Style);
985 verifyFormat("const int *a = foo();", "int const *a = foo();", Style);
986 verifyFormat("const int *const a = foo();", "int const *const a = foo();",
989 verifyFormat("const auto a = foo();", "auto const a = foo();", Style);
990 verifyFormat("const auto *a = foo();", "auto const *a = foo();", Style);
991 verifyFormat("const auto *const a = foo();", "auto const *const a = foo();",
999 Style.QualifierOrder = {"static", "inline", "type", "const", "volatile"};
1002 verifyFormat("static inline int const volatile a;",
1003 "const inline static volatile int a;", Style);
1004 verifyFormat("static inline int const volatile a;",
1005 "volatile inline static const int a;", Style);
1006 verifyFormat("static inline int const volatile a;",
1007 "int const inline static volatile a;", Style);
1008 verifyFormat("static inline int const volatile a;",
1009 "int volatile inline static const a;", Style);
1010 verifyFormat("static inline int const volatile a;",
1011 "const int inline static volatile a;", Style);
1013 verifyFormat("static inline int const volatile *const a;",
1014 "const int inline static volatile *const a;", Style);
1016 verifyFormat("static inline Foo const volatile a;",
1017 "const inline static volatile Foo a;", Style);
1018 verifyFormat("static inline Foo const volatile a;",
1019 "volatile inline static const Foo a;", Style);
1020 verifyFormat("static inline Foo const volatile a;",
1021 "Foo const inline static volatile a;", Style);
1022 verifyFormat("static inline Foo const volatile a;",
1023 "Foo volatile inline static const a;", Style);
1024 verifyFormat("static inline Foo const volatile a;",
1025 "const Foo inline static volatile a;", Style);
1027 verifyFormat("static inline Foo const volatile *const a;",
1028 "const Foo inline static volatile *const a;", Style);
1034 Style.QualifierOrder = {"static", "inline", "type", "const", "volatile"};
1046 std::vector<std::string> RightResult = {"const", "volatile"};
1062 const auto LangOpts = getFormattingLangOpts();
1065 "const static inline auto restrict int double long constexpr friend");
1139 Style.QualifierOrder = {"const", "type"};
1141 verifyFormat("Foo(const Bar &name);", "Foo(Bar const &name);", Style);
1148 Style.QualifierOrder = {"const", "volatile", "type"};
1150 verifyFormat("inline static const int a;", Style);
1152 Style.QualifierOrder = {"static", "const", "type"};
1154 verifyFormat("inline static const int a;", Style);
1155 verifyFormat("static inline const int a;", Style);
1157 verifyFormat("static const int a;", "const static int a;", Style);
1159 Style.QualifierOrder = {"const", "volatile", "type"};
1161 verifyFormat("const volatile int static;", "int volatile static const;",
1163 verifyFormat("const volatile int static;", "int const static volatile;",
1165 verifyFormat("const volatile int static;", "const int static volatile;",
1167 verifyFormat("const volatile Foo static;", "Foo volatile static const;",
1169 verifyFormat("const volatile Foo static;", "Foo const static volatile;",
1171 verifyFormat("const volatile Foo static;", "const Foo static volatile;",
1174 verifyFormat("inline static const Foo;", "inline static Foo const;", Style);
1175 verifyFormat("inline static const Foo;", Style);
1178 verifyFormat("inline const static Foo;", Style);
1179 verifyFormat("const inline static Foo;", Style);
1199 Style.QualifierOrder = {"const", "type"};
1201 verifyFormat("Foo(const unsigned char *bytes)",
1202 "Foo(unsigned const char *bytes)", Style);
1205 Style.QualifierOrder = {"type", "const"};
1207 verifyFormat("Foo(unsigned char const *bytes)",
1208 "Foo(unsigned const char *bytes)", Style);
1215 Style.QualifierOrder = {"static", "const", "type"};
1217 verifyFormat("static const uint32 foo[] = {0, 31};", Style);
1220 verifyFormat("#define MACRO static const", Style);
1223 verifyFormat("using sc = static const", Style);
1230 Style.QualifierOrder = {"static", "const", "type"};
1250 Style.QualifierOrder = {"type", "static", "const"};
1297 Style.QualifierOrder = {"inline", "static", "const", "type"};
1301 "int const inline static a = 0;\n"
1306 "int const inline static a = 0;\n"
1308 "inline static const int a = 0;",
1310 "int const inline static a = 0;\n"
1312 "int const inline static a = 0;",
1319 Style.QualifierOrder = {"type", "const"};
1321 verifyFormat("template <typename T> Foo const f();",
1322 "template <typename T> const Foo f();", Style);
1323 verifyFormat("template <typename T> int const f();",
1324 "template <typename T> const int f();", Style);
1326 verifyFormat("template <T const> t;", "template <const T> t;", Style);
1328 " requires Concept<T const>\n"
1329 "Foo const f();",
1331 " requires Concept<const T>\n"
1332 "const Foo f();",
1334 verifyFormat("TemplateType<T const> t;", "TemplateType<const T> t;", Style);
1335 verifyFormat("TemplateType<Container const> t;",
1336 "TemplateType<const Container> t;", Style);
1342 Style.QualifierOrder = {"const", "volatile", "type"};
1344 verifyFormat("template <typename T> const Foo f();",
1345 "template <typename T> Foo const f();", Style);
1346 verifyFormat("template <typename T> const int f();",
1347 "template <typename T> int const f();", Style);
1349 verifyFormat("template <const T> t;", "template <T const> t;", Style);
1351 " requires Concept<const T>\n"
1352 "const Foo f();",
1354 " requires Concept<T const>\n"
1355 "Foo const f();",
1358 " requires Concept<const T>\n"
1359 "const volatile Foo f();",
1361 " requires Concept<T const>\n"
1362 "volatile const Foo f();",
1364 verifyFormat("TemplateType<const T> t;", "TemplateType<T const> t;", Style);
1365 verifyFormat("TemplateType<const Container> t;",
1366 "TemplateType<Container const> t;", Style);
1372 Style.QualifierOrder = {"const", "volatile", "type"};
1375 verifyFormat("template <typename T> const Foo f();\n"
1376 "template <typename T> Foo const f();",
1377 "template <typename T> Foo const f();\n"
1378 "template <typename T> Foo const f();",
1383 verifyFormat("template <typename T> Foo const f();\n"
1384 "template <typename T> const Foo f();\n"
1385 "template <typename T> Foo const f();",
1386 "template <typename T> Foo const f();\n"
1387 "template <typename T> Foo const f();\n"
1388 "template <typename T> Foo const f();",