[flang] Non-fatal error for repeated access spec
When an access statement repeats the same attribute, make it a non-fatal diagnostic. Also, include the previous specification in the message. resolve11.f90 now illustrates both cases, fatal and non-fatal. Original-commit: flang-compiler/f18@1f567c740a Reviewed-on: https://github.com/flang-compiler/f18/pull/70 Tree-same-pre-rewrite: false
This commit is contained in:
parent
94fa0fd890
commit
cb37c3625a
|
@ -927,10 +927,18 @@ bool ResolveNamesVisitor::Pre(const parser::AccessStmt &x) {
|
|||
// Set the access specification for this name.
|
||||
void ResolveNamesVisitor::SetAccess(const parser::Name &name, Attr attr) {
|
||||
Symbol &symbol{MakeSymbol(name)};
|
||||
if (symbol.attrs().HasAny({Attr::PUBLIC, Attr::PRIVATE})) {
|
||||
Say(name, "The accessibility of '%s' has already been specified"_err_en_US);
|
||||
Attrs &attrs{symbol.attrs()};
|
||||
if (attrs.HasAny({Attr::PUBLIC, Attr::PRIVATE})) {
|
||||
// PUBLIC/PRIVATE already set: make it a fatal error if it changed
|
||||
Attr prev = attrs.test(Attr::PUBLIC) ? Attr::PUBLIC : Attr::PRIVATE;
|
||||
const auto &msg = attr == prev
|
||||
? "The accessibility of '%s' has already been specified as %s"_en_US
|
||||
: "The accessibility of '%s' has already been specified as %s"_err_en_US;
|
||||
Say(Message{name.source,
|
||||
parser::MessageFormattedText{
|
||||
msg, name.ToString().c_str(), EnumToString(prev).c_str()}});
|
||||
} else {
|
||||
symbol.attrs().set(attr);
|
||||
attrs.set(attr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
module m
|
||||
public i
|
||||
!ERROR: The accessibility of 'i' has already been specified
|
||||
integer, private :: j
|
||||
!ERROR: The accessibility of 'i' has already been specified as PUBLIC
|
||||
private i
|
||||
!The accessibility of 'j' has already been specified as PRIVATE
|
||||
private j
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue