This is an archive of the discontinued LLVM Phabricator instance.

Consolidate several functions for checking the std namespace into one function in Decl and one function in DeclContext
ClosedPublic

Authored by rtrieu on Apr 9 2014, 9:45 PM.

Details

Reviewers
rtrieu
Summary

Create Decl::isInStdNamespace() and DeclContext::isStdNamespace() for namespace checking. This will replace six implementations of std namespace checkers.

The std namespace checker in the Itanium mangler has been left since it performs additional checks with its checker.

Diff Detail

Event Timeline

I think you can remove isStdNamespace entirely and keep just isInStdNamespace, with a little tweaking. Maybe also add a flag to it to indicate whether we should consider (non-inline) namespaces within namespace std as "in" std.

lib/AST/DeclBase.cpp
798

I think the getRedeclContext check should be in the callers, not here. Given:

namespace std {

extern "C" { ... }

}

... I would not expect the extern "C" DeclContext to claim to be the std namespace.

803–805

Likewise, I'd expect this to be in isInStdNamespace. I would not expect libc++'s std::__1 to claim to be the std namespace; it's a namespace within that one, sure, but it's not std.

lib/Sema/SemaExceptionSpec.cpp
472–474

Maybe just ExRecord->isInStdNamespace?

lib/Sema/SemaTemplateInstantiateDecl.cpp
883

DCParent->isInStdNamespace?

lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
1516

This doesn't look right; this was checking whether the declaration is transitively within namespace std and now returns false if it's within a (non-inline) namespace within std (such as std::tr1 or std::experimental::file_system).

lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
748

Likewise.

rtrieu updated this revision to Diff 8994.Apr 30 2014, 3:28 PM

Add parameter for checking within inline namespaces. Reworked some of the callsites to keep original behavior.

rtrieu updated this revision to Diff 8996.Apr 30 2014, 3:32 PM

Take two, with proper diff context this time.

+bool DeclContext::isStdNamespace(bool IncludeInlineNamespace) const {
[...]
+ if (!getParent()->getRedeclContext()->isTranslationUnit())
+ return false;

This returns the wrong result if 'std' is itself in an inline namespace,
but I guess we don't need to care about that.

I think the default of IncludeInlineNamespace should be true, not false.
The call in SemaExceptionSpec should set it to 'true', as should all the
calls in the static analyzer, and that only leaves the
SemaTemplateInstantiateDecl call, where we don't care. Can the parameter be
removed altogether?

rtrieu updated this revision to Diff 9725.May 22 2014, 5:28 PM

Remove parameter for checking inside inline namespaces and just do it by default. No tests affected.

LGTM, thanks!

rtrieu accepted this revision.May 27 2014, 7:25 PM
rtrieu added a reviewer: rtrieu.
This revision is now accepted and ready to land.May 27 2014, 7:25 PM
rtrieu closed this revision.May 27 2014, 7:25 PM

Committed at r209708.