[PATCH] D28832: Improve redefinition errors pointing to the same header.
Vassil Vassilev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 12 14:08:29 PDT 2017
v.g.vassilev added a comment.
Here is an example that we recently had where we would be very happy to see better diagnostics:
MessageTypes.h:
#ifndef ROOT_MessageTypes
#define ROOT_MessageTypes
enum EMessageTypes {
kROOTD_OPEN = 2004, //filename follows + mode
};
#endif
module.modulemap:
module "libNet.so" {
requires cplusplus
module "TMessage.h" { header "TMessage.h" export * }
module "TNetFile.h" { header "TNetFile.h" export * }
export *
}
Output:
TNetFile.cxx:1:10: remark: building module 'libNet.so' as '/home/teemperor/Downloads/merge_enum/pcms/3MNDY7KURXTXS/libNet.so-141H35WZHCMDE.pcm' [-Rmodule-build]
#include "TNetFile.h"
^
TNetFile.cxx:1:10: remark: finished building module 'libNet.so' [-Rmodule-build]
TNetFile.cxx:2:10: error: declaration of 'kROOTD_OPEN' must be imported from module 'libNet.so.TMessage.h' before it is required
auto v = kROOTD_OPEN;
^
In module 'libNet.so' imported from TNetFile.cxx:1:
./MessageTypes.h:5:4: note: previous declaration is here
kROOTD_OPEN = 2004, //filename follows + mode
^
1 error generated.
test.sh:
#!/bin/bash
CLANG="/opt/clang/inst/bin/clang"
rm -rf ./pcms/
# Normal clang invocation
#"$CLANG" -cc1 -triple x86_64-apple-macosx10.11.0 -fsyntax-only -I . -std=c++11 -x c++ TNetFile.cxx -nostdsysteminc
# Modules clang invocation
"$CLANG" -cc1 -triple x86_64-apple-macosx10.11.0 -fsyntax-only -I . -std=c++11 -fmodules -fimplicit-module-maps -fmodules-cache-path=./pcms/ -fcolor-diagnostics -fdiagnostics-show-option -fdiagnostics-show-note-include-stack -x c++ TNetFile.cxx -nostdsysteminc -Rmodule-build
TMessage.h:
#ifndef ROOT_TMessage
#define ROOT_TMessage
#include "MessageTypes.h"
#endif
TNetFile.cxx:
#include "TNetFile.h"
auto v = kROOTD_OPEN;
TNetFile.h:
#ifndef ROOT_TNetFile
#define ROOT_TNetFile
#include "MessageTypes.h"
#endif
https://reviews.llvm.org/D28832
More information about the cfe-commits
mailing list