[PATCH] D28832: Improve redefinition errors pointing to the same header.

Bruno Cardoso Lopes via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 17 15:45:11 PST 2017


bruno created this revision.

Diagnostics related to redefinition errors that point to the same header file do not provide much information that helps fixing the issue. In modules context it usually happens because of a non modular include, in non-module context it might happen because of the lack of header guardas. This patch tries to improve this situation by enhancing diagnostics in this particular scenario. If the approach seems reasonable, I can extend it to other relevant redefinition_error diagnostic call sites.

Modules
-------

In file included from x.c:2:
Inputs4/C.h:3:5: error: redefinition of 'c'
int c = 1;

  ^

In module 'X' imported from x.c:1:
Inputs4/C.h:3:5: note: previous definition is here
int c = 1;

  ^

1 warning and 1 error generated.

After this patch

In file included from x.c:2:
Inputs4/C.h:3:5: error: redefinition of 'c'
int c = 1;

  ^

In module 'X' imported from x.c:1:
Inputs4/B.h:3:10: note: 'Inputs4/C.h' included multiple times, additional (likely non-modular) include site in module 'X.B'
#include "C.h"

  ^

1 error generated.
Inputs4/module.modulemap:6:10: note: consider adding 'Inputs4/C.h' as part of 'X.B' definition in

  module B {
         ^

1 error generated.

Without Modules
---------------

In file included from x.c:2:
./a.h:1:5: error: redefinition of 'yyy'
int yyy = 42;

  ^

./a.h:1:5: note: previous definition is here
int yyy = 42;

  ^

1 error generated.

After this patch

In file included from x.c:2:
./a.h:1:5: error: redefinition of 'yyy'
int yyy = 42;

  ^

x.c:1:10: note: './a.h' included multiple times, consider augmenting this header with #ifdef guards
#include "a.h"

  ^

1 error generated.


https://reviews.llvm.org/D28832

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  test/Modules/Inputs/SameHeader/A.h
  test/Modules/Inputs/SameHeader/B.h
  test/Modules/Inputs/SameHeader/C.h
  test/Modules/Inputs/SameHeader/module.modulemap
  test/Modules/redefinition-same-header.m
  test/Sema/redefinition-same-header.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28832.84759.patch
Type: text/x-patch
Size: 6994 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170117/ee62e477/attachment-0001.bin>


More information about the cfe-commits mailing list