fixit-unicode.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file contains code and checks, that should work on any platform.
  2. // There's a set of additional checks for systems with proper support of UTF-8
  3. // on the standard output in fixit-unicode-with-utf8-output.c.
  4. // RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck -strict-whitespace %s
  5. // RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck -check-prefix=CHECK-MACHINE %s
  6. struct Foo {
  7. int bar;
  8. };
  9. // PR13312
  10. void test1() {
  11. struct Foo foo;
  12. foo.bar = 42☃
  13. // CHECK: error: non-ASCII characters are not allowed outside of literals and identifiers
  14. // CHECK: {{^ \^}}
  15. // CHECK: error: expected ';' after expression
  16. // Make sure we emit the fixit right in front of the snowman.
  17. // CHECK: {{^ \^}}
  18. // CHECK: {{^ ;}}
  19. // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-8]]:15-[[@LINE-8]]:18}:""
  20. // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-9]]:15-[[@LINE-9]]:15}:";"
  21. }
  22. int printf(const char *, ...);
  23. void test2() {
  24. printf("∆: %d", 1L);
  25. // CHECK: warning: format specifies type 'int' but the argument has type 'long'
  26. // Don't crash emitting a fixit after the delta.
  27. // CHECK: printf("
  28. // CHECK: : %d", 1L);
  29. // Unfortunately, we can't actually check the location of the printed fixit,
  30. // because different systems will render the delta differently (either as a
  31. // character, or as <U+2206>.) The fixit should line up with the %d regardless.
  32. // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-9]]:16-[[@LINE-9]]:18}:"%ld"
  33. }
  34. void test3() {
  35. int กssss = 42;
  36. int a = กsss; // expected-error{{use of undeclared identifier 'กsss'; did you mean 'กssss'?}}
  37. // CHECK: {{^ \^}}
  38. // CHECK: {{^ [^ ]+ssss}}
  39. // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:17}:"\340\270\201ssss"
  40. int ssกss = 42;
  41. int b = ssกs; // expected-error{{use of undeclared identifier 'ssกs'; did you mean 'ssกss'?}}
  42. // CHECK: {{^ \^}}
  43. // CHECK: {{^ ss.+ss}}
  44. // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:17}:"ss\340\270\201ss"
  45. int s一二三 = 42;
  46. int b一二三四五六七 = ss一二三; // expected-error{{use of undeclared identifier 'ss一二三'; did you mean 's一二三'?}}
  47. // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-1]]:32-[[@LINE-1]]:43}:"s\344\270\200\344\272\214\344\270\211"
  48. int sssssssssก = 42;
  49. int c = sssssssss; // expected-error{{use of undeclared identifier 'sssssssss'; did you mean 'sssssssssก'?}}
  50. // CHECK: {{^ \^}}
  51. // CHECK: {{^ sssssssss.+}}
  52. // CHECK-MACHINE: fix-it:"{{.*}}":{[[@LINE-3]]:11-[[@LINE-3]]:20}:"sssssssss\340\270\201"
  53. }