p1-var.cpp 567 B

123456789101112131415161718192021
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // C++ [basic.def.odr]p1:
  3. // No translation unit shall contain more than one definition of any
  4. // variable, [...].
  5. // Bad: in C++, these are both definitions. None of that C99 tentative stuff.
  6. int i; // expected-note {{previous}}
  7. int i; // expected-error {{redefinition}}
  8. // OK: decl + def
  9. extern int j;
  10. int j;
  11. // OK: def + decl
  12. int k;
  13. extern int k;
  14. // Bad. The important thing here is that we don't emit the diagnostic twice.
  15. int l = 1; // expected-note {{previous}}
  16. int l = 2; // expected-error {{redefinition}}