2009-10-11 17:03:14 +08:00
|
|
|
//===--- SemaExceptionSpec.cpp - C++ Exception Specifications ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides Sema routines for C++ exception specification testing.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-08-26 06:03:47 +08:00
|
|
|
#include "clang/Sema/SemaInternal.h"
|
2014-03-21 05:47:22 +08:00
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
2009-10-11 17:03:14 +08:00
|
|
|
#include "clang/AST/CXXInheritance.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
|
|
|
#include "clang/AST/ExprCXX.h"
|
2010-03-24 15:14:45 +08:00
|
|
|
#include "clang/AST/TypeLoc.h"
|
2010-02-12 15:32:17 +08:00
|
|
|
#include "clang/Basic/Diagnostic.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
2009-10-11 17:03:14 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2012-02-04 21:45:25 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2009-10-11 17:03:14 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
static const FunctionProtoType *GetUnderlyingFunction(QualType T)
|
|
|
|
{
|
|
|
|
if (const PointerType *PtrTy = T->getAs<PointerType>())
|
|
|
|
T = PtrTy->getPointeeType();
|
|
|
|
else if (const ReferenceType *RefTy = T->getAs<ReferenceType>())
|
|
|
|
T = RefTy->getPointeeType();
|
2009-10-14 22:38:54 +08:00
|
|
|
else if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>())
|
|
|
|
T = MPTy->getPointeeType();
|
2009-10-11 17:03:14 +08:00
|
|
|
return T->getAs<FunctionProtoType>();
|
|
|
|
}
|
|
|
|
|
2014-11-14 08:37:55 +08:00
|
|
|
/// HACK: libstdc++ has a bug where it shadows std::swap with a member
|
|
|
|
/// swap function then tries to call std::swap unqualified from the exception
|
|
|
|
/// specification of that function. This function detects whether we're in
|
|
|
|
/// such a case and turns off delay-parsing of exception specifications.
|
|
|
|
bool Sema::isLibstdcxxEagerExceptionSpecHack(const Declarator &D) {
|
|
|
|
auto *RD = dyn_cast<CXXRecordDecl>(CurContext);
|
|
|
|
|
|
|
|
// All the problem cases are member functions named "swap" within class
|
2016-10-20 07:47:37 +08:00
|
|
|
// templates declared directly within namespace std or std::__debug or
|
|
|
|
// std::__profile.
|
|
|
|
if (!RD || !RD->getIdentifier() || !RD->getDescribedClassTemplate() ||
|
2014-11-14 08:37:55 +08:00
|
|
|
!D.getIdentifier() || !D.getIdentifier()->isStr("swap"))
|
|
|
|
return false;
|
|
|
|
|
2016-10-20 07:47:37 +08:00
|
|
|
auto *ND = dyn_cast<NamespaceDecl>(RD->getDeclContext());
|
|
|
|
if (!ND)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool IsInStd = ND->isStdNamespace();
|
|
|
|
if (!IsInStd) {
|
|
|
|
// This isn't a direct member of namespace std, but it might still be
|
|
|
|
// libstdc++'s std::__debug::array or std::__profile::array.
|
|
|
|
IdentifierInfo *II = ND->getIdentifier();
|
|
|
|
if (!II || !(II->isStr("__debug") || II->isStr("__profile")) ||
|
|
|
|
!ND->isInStdNamespace())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-14 08:37:55 +08:00
|
|
|
// Only apply this hack within a system header.
|
|
|
|
if (!Context.getSourceManager().isInSystemHeader(D.getLocStart()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return llvm::StringSwitch<bool>(RD->getIdentifier()->getName())
|
|
|
|
.Case("array", true)
|
2016-10-20 07:47:37 +08:00
|
|
|
.Case("pair", IsInStd)
|
|
|
|
.Case("priority_queue", IsInStd)
|
|
|
|
.Case("stack", IsInStd)
|
|
|
|
.Case("queue", IsInStd)
|
2014-11-14 08:37:55 +08:00
|
|
|
.Default(false);
|
|
|
|
}
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
/// CheckSpecifiedExceptionType - Check if the given type is valid in an
|
|
|
|
/// exception specification. Incomplete types, or pointers to incomplete types
|
|
|
|
/// other than void are not allowed.
|
2012-11-29 06:33:28 +08:00
|
|
|
///
|
|
|
|
/// \param[in,out] T The exception type. This will be decayed to a pointer type
|
|
|
|
/// when the input is an array or a function type.
|
2015-10-04 12:53:55 +08:00
|
|
|
bool Sema::CheckSpecifiedExceptionType(QualType &T, SourceRange Range) {
|
2012-11-29 06:52:42 +08:00
|
|
|
// C++11 [except.spec]p2:
|
|
|
|
// A type cv T, "array of T", or "function returning T" denoted
|
2012-11-29 06:33:28 +08:00
|
|
|
// in an exception-specification is adjusted to type T, "pointer to T", or
|
|
|
|
// "pointer to function returning T", respectively.
|
2012-11-29 06:52:42 +08:00
|
|
|
//
|
|
|
|
// We also apply this rule in C++98.
|
2012-11-29 06:33:28 +08:00
|
|
|
if (T->isArrayType())
|
|
|
|
T = Context.getArrayDecayedType(T);
|
|
|
|
else if (T->isFunctionType())
|
|
|
|
T = Context.getPointerType(T);
|
|
|
|
|
2012-11-29 06:52:42 +08:00
|
|
|
int Kind = 0;
|
2012-11-29 06:33:28 +08:00
|
|
|
QualType PointeeT = T;
|
2012-11-29 06:52:42 +08:00
|
|
|
if (const PointerType *PT = T->getAs<PointerType>()) {
|
|
|
|
PointeeT = PT->getPointeeType();
|
|
|
|
Kind = 1;
|
2009-10-11 17:03:14 +08:00
|
|
|
|
2012-11-29 06:52:42 +08:00
|
|
|
// cv void* is explicitly permitted, despite being a pointer to an
|
|
|
|
// incomplete type.
|
|
|
|
if (PointeeT->isVoidType())
|
|
|
|
return false;
|
|
|
|
} else if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
|
|
|
|
PointeeT = RT->getPointeeType();
|
|
|
|
Kind = 2;
|
|
|
|
|
|
|
|
if (RT->isRValueReferenceType()) {
|
|
|
|
// C++11 [except.spec]p2:
|
|
|
|
// A type denoted in an exception-specification shall not denote [...]
|
|
|
|
// an rvalue reference type.
|
|
|
|
Diag(Range.getBegin(), diag::err_rref_in_exception_spec)
|
|
|
|
<< T << Range;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-11-29 06:33:28 +08:00
|
|
|
|
2012-11-29 06:52:42 +08:00
|
|
|
// C++11 [except.spec]p2:
|
|
|
|
// A type denoted in an exception-specification shall not denote an
|
|
|
|
// incomplete type other than a class currently being defined [...].
|
|
|
|
// A type denoted in an exception-specification shall not denote a
|
|
|
|
// pointer or reference to an incomplete type, other than (cv) void* or a
|
|
|
|
// pointer or reference to a class currently being defined.
|
2016-06-11 02:24:41 +08:00
|
|
|
// In Microsoft mode, downgrade this to a warning.
|
|
|
|
unsigned DiagID = diag::err_incomplete_in_exception_spec;
|
2016-06-11 09:25:04 +08:00
|
|
|
bool ReturnValueOnError = true;
|
|
|
|
if (getLangOpts().MicrosoftExt) {
|
2016-06-11 02:24:41 +08:00
|
|
|
DiagID = diag::ext_incomplete_in_exception_spec;
|
2016-06-11 09:25:04 +08:00
|
|
|
ReturnValueOnError = false;
|
|
|
|
}
|
2012-11-29 06:52:42 +08:00
|
|
|
if (!(PointeeT->isRecordType() &&
|
|
|
|
PointeeT->getAs<RecordType>()->isBeingDefined()) &&
|
2016-06-11 02:24:41 +08:00
|
|
|
RequireCompleteType(Range.getBegin(), PointeeT, DiagID, Kind, Range))
|
2016-06-11 09:25:04 +08:00
|
|
|
return ReturnValueOnError;
|
2009-10-11 17:03:14 +08:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CheckDistantExceptionSpec - Check if the given type is a pointer or pointer
|
|
|
|
/// to member to a function with an exception specification. This means that
|
|
|
|
/// it is invalid to add another level of indirection.
|
|
|
|
bool Sema::CheckDistantExceptionSpec(QualType T) {
|
2016-10-17 01:54:23 +08:00
|
|
|
// C++17 removes this rule in favor of putting exception specifications into
|
|
|
|
// the type system.
|
|
|
|
if (getLangOpts().CPlusPlus1z)
|
|
|
|
return false;
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
if (const PointerType *PT = T->getAs<PointerType>())
|
|
|
|
T = PT->getPointeeType();
|
|
|
|
else if (const MemberPointerType *PT = T->getAs<MemberPointerType>())
|
|
|
|
T = PT->getPointeeType();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const FunctionProtoType *FnT = T->getAs<FunctionProtoType>();
|
|
|
|
if (!FnT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return FnT->hasExceptionSpec();
|
|
|
|
}
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
const FunctionProtoType *
|
|
|
|
Sema::ResolveExceptionSpec(SourceLocation Loc, const FunctionProtoType *FPT) {
|
2014-11-14 04:01:57 +08:00
|
|
|
if (FPT->getExceptionSpecType() == EST_Unparsed) {
|
|
|
|
Diag(Loc, diag::err_exception_spec_not_parsed);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
if (!isUnresolvedExceptionSpec(FPT->getExceptionSpecType()))
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
return FPT;
|
|
|
|
|
|
|
|
FunctionDecl *SourceDecl = FPT->getExceptionSpecDecl();
|
|
|
|
const FunctionProtoType *SourceFPT =
|
|
|
|
SourceDecl->getType()->castAs<FunctionProtoType>();
|
|
|
|
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
// If the exception specification has already been resolved, just return it.
|
|
|
|
if (!isUnresolvedExceptionSpec(SourceFPT->getExceptionSpecType()))
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
return SourceFPT;
|
|
|
|
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
// Compute or instantiate the exception specification now.
|
2013-03-27 08:22:47 +08:00
|
|
|
if (SourceFPT->getExceptionSpecType() == EST_Unevaluated)
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
EvaluateImplicitExceptionSpec(Loc, cast<CXXMethodDecl>(SourceDecl));
|
|
|
|
else
|
|
|
|
InstantiateExceptionSpec(Loc, SourceDecl);
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
2015-07-25 09:19:32 +08:00
|
|
|
const FunctionProtoType *Proto =
|
|
|
|
SourceDecl->getType()->castAs<FunctionProtoType>();
|
|
|
|
if (Proto->getExceptionSpecType() == clang::EST_Unparsed) {
|
|
|
|
Diag(Loc, diag::err_exception_spec_not_parsed);
|
|
|
|
Proto = nullptr;
|
|
|
|
}
|
|
|
|
return Proto;
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2014-08-01 05:57:55 +08:00
|
|
|
void
|
|
|
|
Sema::UpdateExceptionSpec(FunctionDecl *FD,
|
|
|
|
const FunctionProtoType::ExceptionSpecInfo &ESI) {
|
2014-03-21 05:47:22 +08:00
|
|
|
// If we've fully resolved the exception specification, notify listeners.
|
2014-08-01 05:57:55 +08:00
|
|
|
if (!isUnresolvedExceptionSpec(ESI.Type))
|
2014-03-21 05:47:22 +08:00
|
|
|
if (auto *Listener = getASTMutationListener())
|
|
|
|
Listener->ResolvedExceptionSpec(FD);
|
2015-03-23 11:25:59 +08:00
|
|
|
|
|
|
|
for (auto *Redecl : FD->redecls())
|
|
|
|
Context.adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI);
|
2014-03-21 05:47:22 +08:00
|
|
|
}
|
|
|
|
|
2012-10-20 16:26:51 +08:00
|
|
|
/// Determine whether a function has an implicitly-generated exception
|
2012-10-17 07:30:16 +08:00
|
|
|
/// specification.
|
2012-10-20 16:26:51 +08:00
|
|
|
static bool hasImplicitExceptionSpec(FunctionDecl *Decl) {
|
|
|
|
if (!isa<CXXDestructorDecl>(Decl) &&
|
|
|
|
Decl->getDeclName().getCXXOverloadedOperator() != OO_Delete &&
|
|
|
|
Decl->getDeclName().getCXXOverloadedOperator() != OO_Array_Delete)
|
|
|
|
return false;
|
|
|
|
|
2014-02-08 06:51:16 +08:00
|
|
|
// For a function that the user didn't declare:
|
|
|
|
// - if this is a destructor, its exception specification is implicit.
|
|
|
|
// - if this is 'operator delete' or 'operator delete[]', the exception
|
|
|
|
// specification is as-if an explicit exception specification was given
|
|
|
|
// (per [basic.stc.dynamic]p2).
|
2012-10-20 16:26:51 +08:00
|
|
|
if (!Decl->getTypeSourceInfo())
|
2014-02-08 06:51:16 +08:00
|
|
|
return isa<CXXDestructorDecl>(Decl);
|
2012-10-17 07:30:16 +08:00
|
|
|
|
2012-10-20 16:26:51 +08:00
|
|
|
const FunctionProtoType *Ty =
|
|
|
|
Decl->getTypeSourceInfo()->getType()->getAs<FunctionProtoType>();
|
|
|
|
return !Ty->hasExceptionSpec();
|
2012-10-17 07:30:16 +08:00
|
|
|
}
|
|
|
|
|
2010-02-12 15:32:17 +08:00
|
|
|
bool Sema::CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New) {
|
2011-03-16 03:52:30 +08:00
|
|
|
OverloadedOperatorKind OO = New->getDeclName().getCXXOverloadedOperator();
|
|
|
|
bool IsOperatorNew = OO == OO_New || OO == OO_Array_New;
|
2010-03-24 15:14:45 +08:00
|
|
|
bool MissingExceptionSpecification = false;
|
2010-02-12 15:32:17 +08:00
|
|
|
bool MissingEmptyExceptionSpecification = false;
|
2014-02-05 10:37:58 +08:00
|
|
|
|
2011-03-20 07:05:18 +08:00
|
|
|
unsigned DiagID = diag::err_mismatched_exception_spec;
|
2014-02-05 10:37:58 +08:00
|
|
|
bool ReturnValueOnError = true;
|
|
|
|
if (getLangOpts().MicrosoftExt) {
|
2014-07-19 09:39:17 +08:00
|
|
|
DiagID = diag::ext_mismatched_exception_spec;
|
2014-02-05 10:37:58 +08:00
|
|
|
ReturnValueOnError = false;
|
|
|
|
}
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
2012-10-17 07:30:16 +08:00
|
|
|
// Check the types as written: they must match before any exception
|
|
|
|
// specification adjustment is applied.
|
|
|
|
if (!CheckEquivalentExceptionSpec(
|
|
|
|
PDiag(DiagID), PDiag(diag::note_previous_declaration),
|
2012-10-20 16:26:51 +08:00
|
|
|
Old->getType()->getAs<FunctionProtoType>(), Old->getLocation(),
|
|
|
|
New->getType()->getAs<FunctionProtoType>(), New->getLocation(),
|
2012-10-17 07:30:16 +08:00
|
|
|
&MissingExceptionSpecification, &MissingEmptyExceptionSpecification,
|
2012-10-20 16:26:51 +08:00
|
|
|
/*AllowNoexceptAllMatchWithNoSpec=*/true, IsOperatorNew)) {
|
|
|
|
// C++11 [except.spec]p4 [DR1492]:
|
|
|
|
// If a declaration of a function has an implicit
|
|
|
|
// exception-specification, other declarations of the function shall
|
|
|
|
// not specify an exception-specification.
|
2016-09-01 04:38:32 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && getLangOpts().CXXExceptions &&
|
2012-10-20 16:26:51 +08:00
|
|
|
hasImplicitExceptionSpec(Old) != hasImplicitExceptionSpec(New)) {
|
|
|
|
Diag(New->getLocation(), diag::ext_implicit_exception_spec_mismatch)
|
|
|
|
<< hasImplicitExceptionSpec(Old);
|
2015-10-03 18:46:20 +08:00
|
|
|
if (Old->getLocation().isValid())
|
2012-10-20 16:26:51 +08:00
|
|
|
Diag(Old->getLocation(), diag::note_previous_declaration);
|
|
|
|
}
|
2010-02-12 15:32:17 +08:00
|
|
|
return false;
|
2012-10-20 16:26:51 +08:00
|
|
|
}
|
2010-02-12 15:32:17 +08:00
|
|
|
|
2013-06-25 08:46:32 +08:00
|
|
|
// The failure was something other than an missing exception
|
2014-02-05 10:37:58 +08:00
|
|
|
// specification; return an error, except in MS mode where this is a warning.
|
2013-06-25 08:46:32 +08:00
|
|
|
if (!MissingExceptionSpecification)
|
2014-02-05 10:37:58 +08:00
|
|
|
return ReturnValueOnError;
|
2010-02-12 15:32:17 +08:00
|
|
|
|
2012-10-20 16:26:51 +08:00
|
|
|
const FunctionProtoType *NewProto =
|
2013-06-25 08:46:32 +08:00
|
|
|
New->getType()->castAs<FunctionProtoType>();
|
2010-12-14 16:05:40 +08:00
|
|
|
|
2010-02-12 15:32:17 +08:00
|
|
|
// The new function declaration is only missing an empty exception
|
|
|
|
// specification "throw()". If the throw() specification came from a
|
|
|
|
// function in a system header that has C linkage, just add an empty
|
|
|
|
// exception specification to the "new" declaration. This is an
|
|
|
|
// egregious workaround for glibc, which adds throw() specifications
|
|
|
|
// to many libc functions as an optimization. Unfortunately, that
|
|
|
|
// optimization isn't permitted by the C++ standard, so we're forced
|
|
|
|
// to work around it here.
|
2010-12-14 16:05:40 +08:00
|
|
|
if (MissingEmptyExceptionSpecification && NewProto &&
|
2010-03-24 15:14:45 +08:00
|
|
|
(Old->getLocation().isInvalid() ||
|
|
|
|
Context.getSourceManager().isInSystemHeader(Old->getLocation())) &&
|
2010-02-12 15:32:17 +08:00
|
|
|
Old->isExternC()) {
|
2014-08-01 05:57:55 +08:00
|
|
|
New->setType(Context.getFunctionType(
|
|
|
|
NewProto->getReturnType(), NewProto->getParamTypes(),
|
|
|
|
NewProto->getExtProtoInfo().withExceptionSpec(EST_DynamicNone)));
|
2010-02-12 15:32:17 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-25 08:46:32 +08:00
|
|
|
const FunctionProtoType *OldProto =
|
|
|
|
Old->getType()->castAs<FunctionProtoType>();
|
|
|
|
|
2014-08-01 05:57:55 +08:00
|
|
|
FunctionProtoType::ExceptionSpecInfo ESI = OldProto->getExceptionSpecType();
|
|
|
|
if (ESI.Type == EST_Dynamic) {
|
|
|
|
ESI.Exceptions = OldProto->exceptions();
|
2013-06-25 08:46:32 +08:00
|
|
|
}
|
2010-03-24 15:14:45 +08:00
|
|
|
|
2015-09-30 08:48:50 +08:00
|
|
|
if (ESI.Type == EST_ComputedNoexcept) {
|
|
|
|
// For computed noexcept, we can't just take the expression from the old
|
|
|
|
// prototype. It likely contains references to the old prototype's
|
|
|
|
// parameters.
|
|
|
|
New->setInvalidDecl();
|
|
|
|
} else {
|
|
|
|
// Update the type of the function with the appropriate exception
|
|
|
|
// specification.
|
|
|
|
New->setType(Context.getFunctionType(
|
|
|
|
NewProto->getReturnType(), NewProto->getParamTypes(),
|
|
|
|
NewProto->getExtProtoInfo().withExceptionSpec(ESI)));
|
|
|
|
}
|
|
|
|
|
2015-10-21 04:49:21 +08:00
|
|
|
if (getLangOpts().MicrosoftExt && ESI.Type != EST_ComputedNoexcept) {
|
|
|
|
// Allow missing exception specifications in redeclarations as an extension.
|
|
|
|
DiagID = diag::ext_ms_missing_exception_specification;
|
|
|
|
ReturnValueOnError = false;
|
|
|
|
} else if (New->isReplaceableGlobalAllocationFunction() &&
|
|
|
|
ESI.Type != EST_ComputedNoexcept) {
|
|
|
|
// Allow missing exception specifications in redeclarations as an extension,
|
|
|
|
// when declaring a replaceable global allocation function.
|
2015-09-30 08:48:50 +08:00
|
|
|
DiagID = diag::ext_missing_exception_specification;
|
|
|
|
ReturnValueOnError = false;
|
|
|
|
} else {
|
|
|
|
DiagID = diag::err_missing_exception_specification;
|
|
|
|
ReturnValueOnError = true;
|
|
|
|
}
|
2013-06-25 08:46:32 +08:00
|
|
|
|
|
|
|
// Warn about the lack of exception specification.
|
|
|
|
SmallString<128> ExceptionSpecString;
|
|
|
|
llvm::raw_svector_ostream OS(ExceptionSpecString);
|
|
|
|
switch (OldProto->getExceptionSpecType()) {
|
|
|
|
case EST_DynamicNone:
|
|
|
|
OS << "throw()";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EST_Dynamic: {
|
|
|
|
OS << "throw(";
|
|
|
|
bool OnFirstException = true;
|
2014-03-17 23:38:09 +08:00
|
|
|
for (const auto &E : OldProto->exceptions()) {
|
2013-06-25 08:46:32 +08:00
|
|
|
if (OnFirstException)
|
|
|
|
OnFirstException = false;
|
|
|
|
else
|
|
|
|
OS << ", ";
|
|
|
|
|
2014-03-17 23:38:09 +08:00
|
|
|
OS << E.getAsString(getPrintingPolicy());
|
2011-03-12 19:50:43 +08:00
|
|
|
}
|
2013-06-25 08:46:32 +08:00
|
|
|
OS << ")";
|
|
|
|
break;
|
|
|
|
}
|
2011-03-12 19:50:43 +08:00
|
|
|
|
2013-06-25 08:46:32 +08:00
|
|
|
case EST_BasicNoexcept:
|
|
|
|
OS << "noexcept";
|
|
|
|
break;
|
2011-03-12 19:50:43 +08:00
|
|
|
|
2013-06-25 08:46:32 +08:00
|
|
|
case EST_ComputedNoexcept:
|
|
|
|
OS << "noexcept(";
|
2014-06-10 06:53:25 +08:00
|
|
|
assert(OldProto->getNoexceptExpr() != nullptr && "Expected non-null Expr");
|
2014-05-26 14:22:03 +08:00
|
|
|
OldProto->getNoexceptExpr()->printPretty(OS, nullptr, getPrintingPolicy());
|
2013-06-25 08:46:32 +08:00
|
|
|
OS << ")";
|
|
|
|
break;
|
2010-03-24 15:14:45 +08:00
|
|
|
|
2013-06-25 08:46:32 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("This spec type is compatible with none.");
|
|
|
|
}
|
2010-03-24 15:14:45 +08:00
|
|
|
|
2013-06-25 08:46:32 +08:00
|
|
|
SourceLocation FixItLoc;
|
|
|
|
if (TypeSourceInfo *TSInfo = New->getTypeSourceInfo()) {
|
|
|
|
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
|
2015-09-30 08:48:50 +08:00
|
|
|
// FIXME: Preserve enough information so that we can produce a correct fixit
|
|
|
|
// location when there is a trailing return type.
|
|
|
|
if (auto FTLoc = TL.getAs<FunctionProtoTypeLoc>())
|
|
|
|
if (!FTLoc.getTypePtr()->hasTrailingReturn())
|
|
|
|
FixItLoc = getLocForEndOfToken(FTLoc.getLocalRangeEnd());
|
2013-06-25 08:46:32 +08:00
|
|
|
}
|
2010-03-24 15:14:45 +08:00
|
|
|
|
2013-06-25 08:46:32 +08:00
|
|
|
if (FixItLoc.isInvalid())
|
2015-09-30 08:48:50 +08:00
|
|
|
Diag(New->getLocation(), DiagID)
|
2013-06-25 08:46:32 +08:00
|
|
|
<< New << OS.str();
|
|
|
|
else {
|
2015-09-30 08:48:50 +08:00
|
|
|
Diag(New->getLocation(), DiagID)
|
2013-06-25 08:46:32 +08:00
|
|
|
<< New << OS.str()
|
|
|
|
<< FixItHint::CreateInsertion(FixItLoc, " " + OS.str().str());
|
2010-03-24 15:14:45 +08:00
|
|
|
}
|
|
|
|
|
2015-10-03 18:46:20 +08:00
|
|
|
if (Old->getLocation().isValid())
|
2013-06-25 08:46:32 +08:00
|
|
|
Diag(Old->getLocation(), diag::note_previous_declaration);
|
|
|
|
|
2015-09-30 08:48:50 +08:00
|
|
|
return ReturnValueOnError;
|
2010-02-12 15:32:17 +08:00
|
|
|
}
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
/// CheckEquivalentExceptionSpec - Check if the two types have equivalent
|
|
|
|
/// exception specifications. Exception specifications are equivalent if
|
|
|
|
/// they allow exactly the same set of exception types. It does not matter how
|
|
|
|
/// that is achieved. See C++ [except.spec]p2.
|
|
|
|
bool Sema::CheckEquivalentExceptionSpec(
|
|
|
|
const FunctionProtoType *Old, SourceLocation OldLoc,
|
|
|
|
const FunctionProtoType *New, SourceLocation NewLoc) {
|
2011-03-20 07:05:18 +08:00
|
|
|
unsigned DiagID = diag::err_mismatched_exception_spec;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().MicrosoftExt)
|
2014-07-19 09:39:17 +08:00
|
|
|
DiagID = diag::ext_mismatched_exception_spec;
|
2014-02-05 10:37:58 +08:00
|
|
|
bool Result = CheckEquivalentExceptionSpec(PDiag(DiagID),
|
|
|
|
PDiag(diag::note_previous_declaration), Old, OldLoc, New, NewLoc);
|
|
|
|
|
|
|
|
// In Microsoft mode, mismatching exception specifications just cause a warning.
|
|
|
|
if (getLangOpts().MicrosoftExt)
|
|
|
|
return false;
|
|
|
|
return Result;
|
2009-10-11 17:03:14 +08:00
|
|
|
}
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
/// CheckEquivalentExceptionSpec - Check if the two types have compatible
|
|
|
|
/// exception specifications. See C++ [except.spec]p3.
|
2012-10-20 16:26:51 +08:00
|
|
|
///
|
|
|
|
/// \return \c false if the exception specifications match, \c true if there is
|
|
|
|
/// a problem. If \c true is returned, either a diagnostic has already been
|
|
|
|
/// produced or \c *MissingExceptionSpecification is set to \c true.
|
2011-03-12 19:50:43 +08:00
|
|
|
bool Sema::CheckEquivalentExceptionSpec(const PartialDiagnostic &DiagID,
|
2010-03-24 15:14:45 +08:00
|
|
|
const PartialDiagnostic & NoteID,
|
2011-03-12 19:50:43 +08:00
|
|
|
const FunctionProtoType *Old,
|
2010-03-24 15:14:45 +08:00
|
|
|
SourceLocation OldLoc,
|
2011-03-12 19:50:43 +08:00
|
|
|
const FunctionProtoType *New,
|
2010-03-24 15:14:45 +08:00
|
|
|
SourceLocation NewLoc,
|
|
|
|
bool *MissingExceptionSpecification,
|
2011-03-12 19:50:43 +08:00
|
|
|
bool*MissingEmptyExceptionSpecification,
|
2011-03-16 03:52:30 +08:00
|
|
|
bool AllowNoexceptAllMatchWithNoSpec,
|
|
|
|
bool IsOperatorNew) {
|
2010-05-28 16:37:35 +08:00
|
|
|
// Just completely ignore this under -fno-exceptions.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().CXXExceptions)
|
2010-05-28 16:37:35 +08:00
|
|
|
return false;
|
|
|
|
|
2010-03-24 15:14:45 +08:00
|
|
|
if (MissingExceptionSpecification)
|
|
|
|
*MissingExceptionSpecification = false;
|
|
|
|
|
2010-02-12 15:32:17 +08:00
|
|
|
if (MissingEmptyExceptionSpecification)
|
|
|
|
*MissingEmptyExceptionSpecification = false;
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
Old = ResolveExceptionSpec(NewLoc, Old);
|
|
|
|
if (!Old)
|
|
|
|
return false;
|
|
|
|
New = ResolveExceptionSpec(NewLoc, New);
|
|
|
|
if (!New)
|
|
|
|
return false;
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
// C++0x [except.spec]p3: Two exception-specifications are compatible if:
|
|
|
|
// - both are non-throwing, regardless of their form,
|
|
|
|
// - both have the form noexcept(constant-expression) and the constant-
|
|
|
|
// expressions are equivalent,
|
|
|
|
// - both are dynamic-exception-specifications that have the same set of
|
|
|
|
// adjusted types.
|
|
|
|
//
|
2015-07-11 02:25:52 +08:00
|
|
|
// C++0x [except.spec]p12: An exception-specification is non-throwing if it is
|
2011-03-12 19:50:43 +08:00
|
|
|
// of the form throw(), noexcept, or noexcept(constant-expression) where the
|
|
|
|
// constant-expression yields true.
|
|
|
|
//
|
|
|
|
// C++0x [except.spec]p4: If any declaration of a function has an exception-
|
|
|
|
// specifier that is not a noexcept-specification allowing all exceptions,
|
|
|
|
// all declarations [...] of that function shall have a compatible
|
|
|
|
// exception-specification.
|
|
|
|
//
|
|
|
|
// That last point basically means that noexcept(false) matches no spec.
|
|
|
|
// It's considered when AllowNoexceptAllMatchWithNoSpec is true.
|
|
|
|
|
|
|
|
ExceptionSpecificationType OldEST = Old->getExceptionSpecType();
|
|
|
|
ExceptionSpecificationType NewEST = New->getExceptionSpecType();
|
|
|
|
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
assert(!isUnresolvedExceptionSpec(OldEST) &&
|
|
|
|
!isUnresolvedExceptionSpec(NewEST) &&
|
2011-06-12 01:19:42 +08:00
|
|
|
"Shouldn't see unknown exception specifications here");
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
// Shortcut the case where both have no spec.
|
|
|
|
if (OldEST == EST_None && NewEST == EST_None)
|
|
|
|
return false;
|
|
|
|
|
2011-03-14 01:09:40 +08:00
|
|
|
FunctionProtoType::NoexceptResult OldNR = Old->getNoexceptSpec(Context);
|
|
|
|
FunctionProtoType::NoexceptResult NewNR = New->getNoexceptSpec(Context);
|
2011-03-12 19:50:43 +08:00
|
|
|
if (OldNR == FunctionProtoType::NR_BadNoexcept ||
|
|
|
|
NewNR == FunctionProtoType::NR_BadNoexcept)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Dependent noexcept specifiers are compatible with each other, but nothing
|
|
|
|
// else.
|
|
|
|
// One noexcept is compatible with another if the argument is the same
|
|
|
|
if (OldNR == NewNR &&
|
|
|
|
OldNR != FunctionProtoType::NR_NoNoexcept &&
|
|
|
|
NewNR != FunctionProtoType::NR_NoNoexcept)
|
|
|
|
return false;
|
|
|
|
if (OldNR != NewNR &&
|
|
|
|
OldNR != FunctionProtoType::NR_NoNoexcept &&
|
|
|
|
NewNR != FunctionProtoType::NR_NoNoexcept) {
|
|
|
|
Diag(NewLoc, DiagID);
|
2015-02-19 15:28:55 +08:00
|
|
|
if (NoteID.getDiagID() != 0 && OldLoc.isValid())
|
2011-03-12 19:50:43 +08:00
|
|
|
Diag(OldLoc, NoteID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The MS extension throw(...) is compatible with itself.
|
|
|
|
if (OldEST == EST_MSAny && NewEST == EST_MSAny)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// It's also compatible with no spec.
|
|
|
|
if ((OldEST == EST_None && NewEST == EST_MSAny) ||
|
|
|
|
(OldEST == EST_MSAny && NewEST == EST_None))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// It's also compatible with noexcept(false).
|
|
|
|
if (OldEST == EST_MSAny && NewNR == FunctionProtoType::NR_Throw)
|
|
|
|
return false;
|
|
|
|
if (NewEST == EST_MSAny && OldNR == FunctionProtoType::NR_Throw)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// As described above, noexcept(false) matches no spec only for functions.
|
|
|
|
if (AllowNoexceptAllMatchWithNoSpec) {
|
|
|
|
if (OldEST == EST_None && NewNR == FunctionProtoType::NR_Throw)
|
|
|
|
return false;
|
|
|
|
if (NewEST == EST_None && OldNR == FunctionProtoType::NR_Throw)
|
|
|
|
return false;
|
2010-08-30 23:04:51 +08:00
|
|
|
}
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
// Any non-throwing specifications are compatible.
|
|
|
|
bool OldNonThrowing = OldNR == FunctionProtoType::NR_Nothrow ||
|
|
|
|
OldEST == EST_DynamicNone;
|
|
|
|
bool NewNonThrowing = NewNR == FunctionProtoType::NR_Nothrow ||
|
|
|
|
NewEST == EST_DynamicNone;
|
|
|
|
if (OldNonThrowing && NewNonThrowing)
|
2009-10-11 17:03:14 +08:00
|
|
|
return false;
|
2011-03-12 19:50:43 +08:00
|
|
|
|
2011-03-16 03:52:30 +08:00
|
|
|
// As a special compatibility feature, under C++0x we accept no spec and
|
|
|
|
// throw(std::bad_alloc) as equivalent for operator new and operator new[].
|
|
|
|
// This is because the implicit declaration changed, but old code would break.
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && IsOperatorNew) {
|
2014-05-26 14:22:03 +08:00
|
|
|
const FunctionProtoType *WithExceptions = nullptr;
|
2011-03-16 03:52:30 +08:00
|
|
|
if (OldEST == EST_None && NewEST == EST_Dynamic)
|
|
|
|
WithExceptions = New;
|
|
|
|
else if (OldEST == EST_Dynamic && NewEST == EST_None)
|
|
|
|
WithExceptions = Old;
|
|
|
|
if (WithExceptions && WithExceptions->getNumExceptions() == 1) {
|
|
|
|
// One has no spec, the other throw(something). If that something is
|
|
|
|
// std::bad_alloc, all conditions are met.
|
|
|
|
QualType Exception = *WithExceptions->exception_begin();
|
|
|
|
if (CXXRecordDecl *ExRecord = Exception->getAsCXXRecordDecl()) {
|
|
|
|
IdentifierInfo* Name = ExRecord->getIdentifier();
|
|
|
|
if (Name && Name->getName() == "bad_alloc") {
|
|
|
|
// It's called bad_alloc, but is it in std?
|
2014-05-28 10:16:01 +08:00
|
|
|
if (ExRecord->isInStdNamespace()) {
|
|
|
|
return false;
|
2011-03-16 03:52:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
// At this point, the only remaining valid case is two matching dynamic
|
|
|
|
// specifications. We return here unless both specifications are dynamic.
|
|
|
|
if (OldEST != EST_Dynamic || NewEST != EST_Dynamic) {
|
2010-03-24 15:14:45 +08:00
|
|
|
if (MissingExceptionSpecification && Old->hasExceptionSpec() &&
|
2010-02-12 15:32:17 +08:00
|
|
|
!New->hasExceptionSpec()) {
|
2010-03-24 15:14:45 +08:00
|
|
|
// The old type has an exception specification of some sort, but
|
|
|
|
// the new type does not.
|
|
|
|
*MissingExceptionSpecification = true;
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
if (MissingEmptyExceptionSpecification && OldNonThrowing) {
|
|
|
|
// The old type has a throw() or noexcept(true) exception specification
|
|
|
|
// and the new type has no exception specification, and the caller asked
|
2010-03-24 15:14:45 +08:00
|
|
|
// to handle this itself.
|
|
|
|
*MissingEmptyExceptionSpecification = true;
|
|
|
|
}
|
|
|
|
|
2010-02-12 15:32:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
Diag(NewLoc, DiagID);
|
2015-02-19 15:28:55 +08:00
|
|
|
if (NoteID.getDiagID() != 0 && OldLoc.isValid())
|
2009-10-11 17:03:14 +08:00
|
|
|
Diag(OldLoc, NoteID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
assert(OldEST == EST_Dynamic && NewEST == EST_Dynamic &&
|
|
|
|
"Exception compatibility logic error: non-dynamic spec slipped through.");
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
bool Success = true;
|
2011-03-12 19:50:43 +08:00
|
|
|
// Both have a dynamic exception spec. Collect the first set, then compare
|
2009-10-11 17:03:14 +08:00
|
|
|
// to the second.
|
2009-10-14 23:06:25 +08:00
|
|
|
llvm::SmallPtrSet<CanQualType, 8> OldTypes, NewTypes;
|
2014-03-17 23:38:09 +08:00
|
|
|
for (const auto &I : Old->exceptions())
|
|
|
|
OldTypes.insert(Context.getCanonicalType(I).getUnqualifiedType());
|
2009-10-11 17:03:14 +08:00
|
|
|
|
2014-03-17 23:38:09 +08:00
|
|
|
for (const auto &I : New->exceptions()) {
|
|
|
|
CanQualType TypePtr = Context.getCanonicalType(I).getUnqualifiedType();
|
2009-10-11 17:11:23 +08:00
|
|
|
if(OldTypes.count(TypePtr))
|
|
|
|
NewTypes.insert(TypePtr);
|
|
|
|
else
|
|
|
|
Success = false;
|
|
|
|
}
|
2009-10-11 17:03:14 +08:00
|
|
|
|
2009-10-11 17:11:23 +08:00
|
|
|
Success = Success && OldTypes.size() == NewTypes.size();
|
2009-10-11 17:03:14 +08:00
|
|
|
|
|
|
|
if (Success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Diag(NewLoc, DiagID);
|
2015-02-19 15:28:55 +08:00
|
|
|
if (NoteID.getDiagID() != 0 && OldLoc.isValid())
|
2009-10-11 17:03:14 +08:00
|
|
|
Diag(OldLoc, NoteID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CheckExceptionSpecSubset - Check whether the second function type's
|
|
|
|
/// exception specification is a subset (or equivalent) of the first function
|
|
|
|
/// type. This is used by override and pointer assignment checks.
|
2009-10-15 00:09:29 +08:00
|
|
|
bool Sema::CheckExceptionSpecSubset(
|
|
|
|
const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
|
2009-10-11 17:03:14 +08:00
|
|
|
const FunctionProtoType *Superset, SourceLocation SuperLoc,
|
|
|
|
const FunctionProtoType *Subset, SourceLocation SubLoc) {
|
2010-05-28 16:37:35 +08:00
|
|
|
|
|
|
|
// Just auto-succeed under -fno-exceptions.
|
2012-03-11 15:00:24 +08:00
|
|
|
if (!getLangOpts().CXXExceptions)
|
2010-05-28 16:37:35 +08:00
|
|
|
return false;
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
// FIXME: As usual, we could be more specific in our error messages, but
|
|
|
|
// that better waits until we've got types with source locations.
|
|
|
|
|
|
|
|
if (!SubLoc.isValid())
|
|
|
|
SubLoc = SuperLoc;
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
// Resolve the exception specifications, if needed.
|
|
|
|
Superset = ResolveExceptionSpec(SuperLoc, Superset);
|
|
|
|
if (!Superset)
|
|
|
|
return false;
|
|
|
|
Subset = ResolveExceptionSpec(SubLoc, Subset);
|
|
|
|
if (!Subset)
|
|
|
|
return false;
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
ExceptionSpecificationType SuperEST = Superset->getExceptionSpecType();
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
// If superset contains everything, we're done.
|
2011-03-12 19:50:43 +08:00
|
|
|
if (SuperEST == EST_None || SuperEST == EST_MSAny)
|
|
|
|
return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
|
|
|
|
|
|
|
|
// If there are dependent noexcept specs, assume everything is fine. Unlike
|
|
|
|
// with the equivalency check, this is safe in this case, because we don't
|
|
|
|
// want to merge declarations. Checks after instantiation will catch any
|
|
|
|
// omissions we make here.
|
|
|
|
// We also shortcut checking if a noexcept expression was bad.
|
|
|
|
|
2011-03-14 01:09:40 +08:00
|
|
|
FunctionProtoType::NoexceptResult SuperNR =Superset->getNoexceptSpec(Context);
|
2011-03-12 19:50:43 +08:00
|
|
|
if (SuperNR == FunctionProtoType::NR_BadNoexcept ||
|
|
|
|
SuperNR == FunctionProtoType::NR_Dependent)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Another case of the superset containing everything.
|
|
|
|
if (SuperNR == FunctionProtoType::NR_Throw)
|
2009-10-11 17:03:14 +08:00
|
|
|
return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
ExceptionSpecificationType SubEST = Subset->getExceptionSpecType();
|
|
|
|
|
Final piece of core issue 1330: delay computing the exception specification of
a defaulted special member function until the exception specification is needed
(using the same criteria used for the delayed instantiation of exception
specifications for function temploids).
EST_Delayed is now EST_Unevaluated (using 1330's terminology), and, like
EST_Uninstantiated, carries a pointer to the FunctionDecl which will be used to
resolve the exception specification.
This is enabled for all C++ modes: it's a little faster in the case where the
exception specification isn't used, allows our C++11-in-C++98 extensions to
work, and is still correct for C++98, since in that mode the computation of the
exception specification can't fail.
The diagnostics here aren't great (in particular, we should include implicit
evaluation of exception specifications for defaulted special members in the
template instantiation backtraces), but they're not much worse than before.
Our approach to the problem of cycles between in-class initializers and the
exception specification for a defaulted default constructor is modified a
little by this change -- we now reject any odr-use of a defaulted default
constructor if that constructor uses an in-class initializer and the use is in
an in-class initialzer which is declared lexically earlier. This is a closer
approximation to the current draft solution in core issue 1351, but isn't an
exact match (but the current draft wording isn't reasonable, so that's to be
expected).
llvm-svn: 160847
2012-07-27 12:22:15 +08:00
|
|
|
assert(!isUnresolvedExceptionSpec(SuperEST) &&
|
|
|
|
!isUnresolvedExceptionSpec(SubEST) &&
|
2011-06-12 01:19:42 +08:00
|
|
|
"Shouldn't see unknown exception specifications here");
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
// It does not. If the subset contains everything, we've failed.
|
2011-03-12 19:50:43 +08:00
|
|
|
if (SubEST == EST_None || SubEST == EST_MSAny) {
|
|
|
|
Diag(SubLoc, DiagID);
|
|
|
|
if (NoteID.getDiagID() != 0)
|
|
|
|
Diag(SuperLoc, NoteID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-14 01:09:40 +08:00
|
|
|
FunctionProtoType::NoexceptResult SubNR = Subset->getNoexceptSpec(Context);
|
2011-03-12 19:50:43 +08:00
|
|
|
if (SubNR == FunctionProtoType::NR_BadNoexcept ||
|
|
|
|
SubNR == FunctionProtoType::NR_Dependent)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Another case of the subset containing everything.
|
|
|
|
if (SubNR == FunctionProtoType::NR_Throw) {
|
|
|
|
Diag(SubLoc, DiagID);
|
|
|
|
if (NoteID.getDiagID() != 0)
|
|
|
|
Diag(SuperLoc, NoteID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the subset contains nothing, we're done.
|
|
|
|
if (SubEST == EST_DynamicNone || SubNR == FunctionProtoType::NR_Nothrow)
|
|
|
|
return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
|
|
|
|
|
|
|
|
// Otherwise, if the superset contains nothing, we've failed.
|
|
|
|
if (SuperEST == EST_DynamicNone || SuperNR == FunctionProtoType::NR_Nothrow) {
|
2009-10-11 17:03:14 +08:00
|
|
|
Diag(SubLoc, DiagID);
|
2009-10-15 00:09:29 +08:00
|
|
|
if (NoteID.getDiagID() != 0)
|
2009-10-11 17:03:14 +08:00
|
|
|
Diag(SuperLoc, NoteID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-12 19:50:43 +08:00
|
|
|
assert(SuperEST == EST_Dynamic && SubEST == EST_Dynamic &&
|
|
|
|
"Exception spec subset: non-dynamic case slipped through.");
|
|
|
|
|
|
|
|
// Neither contains everything or nothing. Do a proper comparison.
|
2014-03-17 23:38:09 +08:00
|
|
|
for (const auto &SubI : Subset->exceptions()) {
|
2009-10-11 17:03:14 +08:00
|
|
|
// Take one type from the subset.
|
2014-03-17 23:38:09 +08:00
|
|
|
QualType CanonicalSubT = Context.getCanonicalType(SubI);
|
2009-10-14 22:38:54 +08:00
|
|
|
// Unwrap pointers and references so that we can do checks within a class
|
|
|
|
// hierarchy. Don't unwrap member pointers; they don't have hierarchy
|
|
|
|
// conversions on the pointee.
|
2009-10-11 17:03:14 +08:00
|
|
|
bool SubIsPointer = false;
|
|
|
|
if (const ReferenceType *RefTy = CanonicalSubT->getAs<ReferenceType>())
|
|
|
|
CanonicalSubT = RefTy->getPointeeType();
|
|
|
|
if (const PointerType *PtrTy = CanonicalSubT->getAs<PointerType>()) {
|
|
|
|
CanonicalSubT = PtrTy->getPointeeType();
|
|
|
|
SubIsPointer = true;
|
|
|
|
}
|
|
|
|
bool SubIsClass = CanonicalSubT->isRecordType();
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
llvm-svn: 88969
2009-11-17 05:35:15 +08:00
|
|
|
CanonicalSubT = CanonicalSubT.getLocalUnqualifiedType();
|
2009-10-11 17:03:14 +08:00
|
|
|
|
|
|
|
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
|
|
|
|
/*DetectVirtual=*/false);
|
|
|
|
|
|
|
|
bool Contained = false;
|
|
|
|
// Make sure it's in the superset.
|
2014-03-17 23:38:09 +08:00
|
|
|
for (const auto &SuperI : Superset->exceptions()) {
|
|
|
|
QualType CanonicalSuperT = Context.getCanonicalType(SuperI);
|
2009-10-11 17:03:14 +08:00
|
|
|
// SubT must be SuperT or derived from it, or pointer or reference to
|
|
|
|
// such types.
|
|
|
|
if (const ReferenceType *RefTy = CanonicalSuperT->getAs<ReferenceType>())
|
|
|
|
CanonicalSuperT = RefTy->getPointeeType();
|
|
|
|
if (SubIsPointer) {
|
|
|
|
if (const PointerType *PtrTy = CanonicalSuperT->getAs<PointerType>())
|
|
|
|
CanonicalSuperT = PtrTy->getPointeeType();
|
|
|
|
else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
First part of changes to eliminate problems with cv-qualifiers and
sugared types. The basic problem is that our qualifier accessors
(getQualifiers, getCVRQualifiers, isConstQualified, etc.) only look at
the current QualType and not at any qualifiers that come from sugared
types, meaning that we won't see these qualifiers through, e.g.,
typedefs:
typedef const int CInt;
typedef CInt Self;
Self.isConstQualified() currently returns false!
Various bugs (e.g., PR5383) have cropped up all over the front end due
to such problems. I'm addressing this problem by splitting each
qualifier accessor into two versions:
- the "local" version only returns qualifiers on this particular
QualType instance
- the "normal" version that will eventually combine qualifiers from this
QualType instance with the qualifiers on the canonical type to
produce the full set of qualifiers.
This commit adds the local versions and switches a few callers from
the "normal" version (e.g., isConstQualified) over to the "local"
version (e.g., isLocalConstQualified) when that is the right thing to
do, e.g., because we're printing or serializing the qualifiers. Also,
switch a bunch of
Context.getCanonicalType(T1).getUnqualifiedType() == Context.getCanonicalType(T2).getQualifiedType()
expressions over to
Context.hasSameUnqualifiedType(T1, T2)
llvm-svn: 88969
2009-11-17 05:35:15 +08:00
|
|
|
CanonicalSuperT = CanonicalSuperT.getLocalUnqualifiedType();
|
2009-10-11 17:03:14 +08:00
|
|
|
// If the types are the same, move on to the next type in the subset.
|
|
|
|
if (CanonicalSubT == CanonicalSuperT) {
|
|
|
|
Contained = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise we need to check the inheritance.
|
|
|
|
if (!SubIsClass || !CanonicalSuperT->isRecordType())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Paths.clear();
|
2015-12-19 05:45:41 +08:00
|
|
|
if (!IsDerivedFrom(SubLoc, CanonicalSubT, CanonicalSuperT, Paths))
|
2009-10-11 17:03:14 +08:00
|
|
|
continue;
|
|
|
|
|
2010-05-22 04:29:55 +08:00
|
|
|
if (Paths.isAmbiguous(Context.getCanonicalType(CanonicalSuperT)))
|
2009-10-11 17:03:14 +08:00
|
|
|
continue;
|
|
|
|
|
2010-02-10 17:31:12 +08:00
|
|
|
// Do this check from a context without privileges.
|
2010-03-16 13:22:47 +08:00
|
|
|
switch (CheckBaseClassAccess(SourceLocation(),
|
2010-02-10 17:31:12 +08:00
|
|
|
CanonicalSuperT, CanonicalSubT,
|
|
|
|
Paths.front(),
|
2010-03-16 13:22:47 +08:00
|
|
|
/*Diagnostic*/ 0,
|
2010-02-10 17:31:12 +08:00
|
|
|
/*ForceCheck*/ true,
|
2010-03-16 13:22:47 +08:00
|
|
|
/*ForceUnprivileged*/ true)) {
|
2010-02-10 17:31:12 +08:00
|
|
|
case AR_accessible: break;
|
|
|
|
case AR_inaccessible: continue;
|
|
|
|
case AR_dependent:
|
|
|
|
llvm_unreachable("access check dependent for unprivileged context");
|
|
|
|
case AR_delayed:
|
|
|
|
llvm_unreachable("access check delayed in non-declaration");
|
|
|
|
}
|
2009-10-11 17:03:14 +08:00
|
|
|
|
|
|
|
Contained = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!Contained) {
|
|
|
|
Diag(SubLoc, DiagID);
|
2009-10-15 00:09:29 +08:00
|
|
|
if (NoteID.getDiagID() != 0)
|
2009-10-11 17:03:14 +08:00
|
|
|
Diag(SuperLoc, NoteID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// We've run half the gauntlet.
|
|
|
|
return CheckParamExceptionSpec(NoteID, Superset, SuperLoc, Subset, SubLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool CheckSpecForTypesEquivalent(Sema &S,
|
2009-10-15 00:09:29 +08:00
|
|
|
const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID,
|
2009-10-11 17:03:14 +08:00
|
|
|
QualType Target, SourceLocation TargetLoc,
|
|
|
|
QualType Source, SourceLocation SourceLoc)
|
|
|
|
{
|
|
|
|
const FunctionProtoType *TFunc = GetUnderlyingFunction(Target);
|
|
|
|
if (!TFunc)
|
|
|
|
return false;
|
|
|
|
const FunctionProtoType *SFunc = GetUnderlyingFunction(Source);
|
|
|
|
if (!SFunc)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return S.CheckEquivalentExceptionSpec(DiagID, NoteID, TFunc, TargetLoc,
|
|
|
|
SFunc, SourceLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// CheckParamExceptionSpec - Check if the parameter and return types of the
|
|
|
|
/// two functions have equivalent exception specs. This is part of the
|
|
|
|
/// assignment and override compatibility check. We do not check the parameters
|
|
|
|
/// of parameter function pointers recursively, as no sane programmer would
|
|
|
|
/// even be able to write such a function type.
|
2014-11-12 10:00:47 +08:00
|
|
|
bool Sema::CheckParamExceptionSpec(const PartialDiagnostic &NoteID,
|
|
|
|
const FunctionProtoType *Target,
|
|
|
|
SourceLocation TargetLoc,
|
|
|
|
const FunctionProtoType *Source,
|
|
|
|
SourceLocation SourceLoc) {
|
2014-01-26 00:55:45 +08:00
|
|
|
if (CheckSpecForTypesEquivalent(
|
|
|
|
*this, PDiag(diag::err_deep_exception_specs_differ) << 0, PDiag(),
|
|
|
|
Target->getReturnType(), TargetLoc, Source->getReturnType(),
|
|
|
|
SourceLoc))
|
2009-10-11 17:03:14 +08:00
|
|
|
return true;
|
|
|
|
|
2009-10-15 00:09:29 +08:00
|
|
|
// We shouldn't even be testing this unless the arguments are otherwise
|
2009-10-11 17:03:14 +08:00
|
|
|
// compatible.
|
2014-01-21 04:26:09 +08:00
|
|
|
assert(Target->getNumParams() == Source->getNumParams() &&
|
2009-10-11 17:03:14 +08:00
|
|
|
"Functions have different argument counts.");
|
2014-01-21 04:26:09 +08:00
|
|
|
for (unsigned i = 0, E = Target->getNumParams(); i != E; ++i) {
|
|
|
|
if (CheckSpecForTypesEquivalent(
|
|
|
|
*this, PDiag(diag::err_deep_exception_specs_differ) << 1, PDiag(),
|
|
|
|
Target->getParamType(i), TargetLoc, Source->getParamType(i),
|
|
|
|
SourceLoc))
|
2009-10-11 17:03:14 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-12 10:00:47 +08:00
|
|
|
bool Sema::CheckExceptionSpecCompatibility(Expr *From, QualType ToType) {
|
2009-10-11 17:03:14 +08:00
|
|
|
// First we check for applicability.
|
|
|
|
// Target type must be a function, function pointer or function reference.
|
|
|
|
const FunctionProtoType *ToFunc = GetUnderlyingFunction(ToType);
|
2014-11-12 10:00:47 +08:00
|
|
|
if (!ToFunc || ToFunc->hasDependentExceptionSpec())
|
2009-10-11 17:03:14 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// SourceType must be a function or function pointer.
|
|
|
|
const FunctionProtoType *FromFunc = GetUnderlyingFunction(From->getType());
|
2014-11-12 10:00:47 +08:00
|
|
|
if (!FromFunc || FromFunc->hasDependentExceptionSpec())
|
2009-10-11 17:03:14 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Now we've got the correct types on both sides, check their compatibility.
|
|
|
|
// This means that the source of the conversion can only throw a subset of
|
|
|
|
// the exceptions of the target, and any exception specs on arguments or
|
|
|
|
// return types must be equivalent.
|
2014-11-12 10:00:47 +08:00
|
|
|
//
|
|
|
|
// FIXME: If there is a nested dependent exception specification, we should
|
|
|
|
// not be checking it here. This is fine:
|
|
|
|
// template<typename T> void f() {
|
|
|
|
// void (*p)(void (*) throw(T));
|
|
|
|
// void (*q)(void (*) throw(int)) = p;
|
|
|
|
// }
|
|
|
|
// ... because it might be instantiated with T=int.
|
2010-03-30 07:34:08 +08:00
|
|
|
return CheckExceptionSpecSubset(PDiag(diag::err_incompatible_exception_specs),
|
|
|
|
PDiag(), ToFunc,
|
|
|
|
From->getSourceRange().getBegin(),
|
2009-10-11 17:03:14 +08:00
|
|
|
FromFunc, SourceLocation());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sema::CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New,
|
|
|
|
const CXXMethodDecl *Old) {
|
2014-11-22 11:09:05 +08:00
|
|
|
// If the new exception specification hasn't been parsed yet, skip the check.
|
|
|
|
// We'll get called again once it's been parsed.
|
|
|
|
if (New->getType()->castAs<FunctionProtoType>()->getExceptionSpecType() ==
|
|
|
|
EST_Unparsed)
|
|
|
|
return false;
|
2013-01-02 19:42:31 +08:00
|
|
|
if (getLangOpts().CPlusPlus11 && isa<CXXDestructorDecl>(New)) {
|
2011-05-20 13:57:18 +08:00
|
|
|
// Don't check uninstantiated template destructors at all. We can only
|
|
|
|
// synthesize correct specs after the template is instantiated.
|
|
|
|
if (New->getParent()->isDependentType())
|
|
|
|
return false;
|
|
|
|
if (New->getParent()->isBeingDefined()) {
|
|
|
|
// The destructor might be updated once the definition is finished. So
|
|
|
|
// remember it and check later.
|
2014-11-22 11:09:05 +08:00
|
|
|
DelayedExceptionSpecChecks.push_back(std::make_pair(New, Old));
|
2011-05-20 13:57:18 +08:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-19 13:13:44 +08:00
|
|
|
}
|
2014-11-22 11:09:05 +08:00
|
|
|
// If the old exception specification hasn't been parsed yet, remember that
|
|
|
|
// we need to perform this check when we get to the end of the outermost
|
|
|
|
// lexically-surrounding class.
|
|
|
|
if (Old->getType()->castAs<FunctionProtoType>()->getExceptionSpecType() ==
|
|
|
|
EST_Unparsed) {
|
|
|
|
DelayedExceptionSpecChecks.push_back(std::make_pair(New, Old));
|
2014-11-14 04:01:57 +08:00
|
|
|
return false;
|
2014-11-22 11:09:05 +08:00
|
|
|
}
|
2011-05-24 10:11:43 +08:00
|
|
|
unsigned DiagID = diag::err_override_exception_spec;
|
2012-03-11 15:00:24 +08:00
|
|
|
if (getLangOpts().MicrosoftExt)
|
2014-07-19 09:39:17 +08:00
|
|
|
DiagID = diag::ext_override_exception_spec;
|
2011-05-24 10:11:43 +08:00
|
|
|
return CheckExceptionSpecSubset(PDiag(DiagID),
|
2010-03-30 07:34:08 +08:00
|
|
|
PDiag(diag::note_overridden_virtual_function),
|
2009-10-11 17:03:14 +08:00
|
|
|
Old->getType()->getAs<FunctionProtoType>(),
|
|
|
|
Old->getLocation(),
|
|
|
|
New->getType()->getAs<FunctionProtoType>(),
|
|
|
|
New->getLocation());
|
|
|
|
}
|
|
|
|
|
2015-07-03 05:03:14 +08:00
|
|
|
static CanThrowResult canSubExprsThrow(Sema &S, const Expr *E) {
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
CanThrowResult R = CT_Cannot;
|
2015-07-03 05:03:14 +08:00
|
|
|
for (const Stmt *SubStmt : E->children()) {
|
|
|
|
R = mergeCanThrow(R, S.canThrow(cast<Expr>(SubStmt)));
|
|
|
|
if (R == CT_Can)
|
|
|
|
break;
|
|
|
|
}
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
return R;
|
|
|
|
}
|
|
|
|
|
2013-06-25 09:24:22 +08:00
|
|
|
static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D) {
|
|
|
|
assert(D && "Expected decl");
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
// See if we can get a function type from the decl somehow.
|
|
|
|
const ValueDecl *VD = dyn_cast<ValueDecl>(D);
|
|
|
|
if (!VD) // If we have no clue what we're calling, assume the worst.
|
|
|
|
return CT_Can;
|
|
|
|
|
|
|
|
// As an extension, we assume that __attribute__((nothrow)) functions don't
|
|
|
|
// throw.
|
|
|
|
if (isa<FunctionDecl>(D) && D->hasAttr<NoThrowAttr>())
|
|
|
|
return CT_Cannot;
|
|
|
|
|
|
|
|
QualType T = VD->getType();
|
|
|
|
const FunctionProtoType *FT;
|
|
|
|
if ((FT = T->getAs<FunctionProtoType>())) {
|
|
|
|
} else if (const PointerType *PT = T->getAs<PointerType>())
|
|
|
|
FT = PT->getPointeeType()->getAs<FunctionProtoType>();
|
|
|
|
else if (const ReferenceType *RT = T->getAs<ReferenceType>())
|
|
|
|
FT = RT->getPointeeType()->getAs<FunctionProtoType>();
|
|
|
|
else if (const MemberPointerType *MT = T->getAs<MemberPointerType>())
|
|
|
|
FT = MT->getPointeeType()->getAs<FunctionProtoType>();
|
|
|
|
else if (const BlockPointerType *BT = T->getAs<BlockPointerType>())
|
|
|
|
FT = BT->getPointeeType()->getAs<FunctionProtoType>();
|
|
|
|
|
|
|
|
if (!FT)
|
|
|
|
return CT_Can;
|
|
|
|
|
|
|
|
FT = S.ResolveExceptionSpec(E->getLocStart(), FT);
|
|
|
|
if (!FT)
|
|
|
|
return CT_Can;
|
|
|
|
|
|
|
|
return FT->isNothrow(S.Context) ? CT_Cannot : CT_Can;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CanThrowResult canDynamicCastThrow(const CXXDynamicCastExpr *DC) {
|
|
|
|
if (DC->isTypeDependent())
|
|
|
|
return CT_Dependent;
|
|
|
|
|
|
|
|
if (!DC->getTypeAsWritten()->isReferenceType())
|
|
|
|
return CT_Cannot;
|
|
|
|
|
|
|
|
if (DC->getSubExpr()->isTypeDependent())
|
|
|
|
return CT_Dependent;
|
|
|
|
|
|
|
|
return DC->getCastKind() == clang::CK_Dynamic? CT_Can : CT_Cannot;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CanThrowResult canTypeidThrow(Sema &S, const CXXTypeidExpr *DC) {
|
|
|
|
if (DC->isTypeOperand())
|
|
|
|
return CT_Cannot;
|
|
|
|
|
|
|
|
Expr *Op = DC->getExprOperand();
|
|
|
|
if (Op->isTypeDependent())
|
|
|
|
return CT_Dependent;
|
|
|
|
|
|
|
|
const RecordType *RT = Op->getType()->getAs<RecordType>();
|
|
|
|
if (!RT)
|
|
|
|
return CT_Cannot;
|
|
|
|
|
|
|
|
if (!cast<CXXRecordDecl>(RT->getDecl())->isPolymorphic())
|
|
|
|
return CT_Cannot;
|
|
|
|
|
|
|
|
if (Op->Classify(S.Context).isPRValue())
|
|
|
|
return CT_Cannot;
|
|
|
|
|
|
|
|
return CT_Can;
|
|
|
|
}
|
|
|
|
|
|
|
|
CanThrowResult Sema::canThrow(const Expr *E) {
|
|
|
|
// C++ [expr.unary.noexcept]p3:
|
|
|
|
// [Can throw] if in a potentially-evaluated context the expression would
|
|
|
|
// contain:
|
|
|
|
switch (E->getStmtClass()) {
|
|
|
|
case Expr::CXXThrowExprClass:
|
|
|
|
// - a potentially evaluated throw-expression
|
|
|
|
return CT_Can;
|
|
|
|
|
|
|
|
case Expr::CXXDynamicCastExprClass: {
|
|
|
|
// - a potentially evaluated dynamic_cast expression dynamic_cast<T>(v),
|
|
|
|
// where T is a reference type, that requires a run-time check
|
|
|
|
CanThrowResult CT = canDynamicCastThrow(cast<CXXDynamicCastExpr>(E));
|
|
|
|
if (CT == CT_Can)
|
|
|
|
return CT;
|
|
|
|
return mergeCanThrow(CT, canSubExprsThrow(*this, E));
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXTypeidExprClass:
|
|
|
|
// - a potentially evaluated typeid expression applied to a glvalue
|
|
|
|
// expression whose type is a polymorphic class type
|
|
|
|
return canTypeidThrow(*this, cast<CXXTypeidExpr>(E));
|
|
|
|
|
|
|
|
// - a potentially evaluated call to a function, member function, function
|
|
|
|
// pointer, or member function pointer that does not have a non-throwing
|
|
|
|
// exception-specification
|
|
|
|
case Expr::CallExprClass:
|
|
|
|
case Expr::CXXMemberCallExprClass:
|
|
|
|
case Expr::CXXOperatorCallExprClass:
|
|
|
|
case Expr::UserDefinedLiteralClass: {
|
|
|
|
const CallExpr *CE = cast<CallExpr>(E);
|
|
|
|
CanThrowResult CT;
|
|
|
|
if (E->isTypeDependent())
|
|
|
|
CT = CT_Dependent;
|
|
|
|
else if (isa<CXXPseudoDestructorExpr>(CE->getCallee()->IgnoreParens()))
|
|
|
|
CT = CT_Cannot;
|
2013-06-25 09:55:41 +08:00
|
|
|
else if (CE->getCalleeDecl())
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
CT = canCalleeThrow(*this, E, CE->getCalleeDecl());
|
2013-06-25 09:55:41 +08:00
|
|
|
else
|
|
|
|
CT = CT_Can;
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
if (CT == CT_Can)
|
|
|
|
return CT;
|
|
|
|
return mergeCanThrow(CT, canSubExprsThrow(*this, E));
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXConstructExprClass:
|
|
|
|
case Expr::CXXTemporaryObjectExprClass: {
|
|
|
|
CanThrowResult CT = canCalleeThrow(*this, E,
|
|
|
|
cast<CXXConstructExpr>(E)->getConstructor());
|
|
|
|
if (CT == CT_Can)
|
|
|
|
return CT;
|
|
|
|
return mergeCanThrow(CT, canSubExprsThrow(*this, E));
|
|
|
|
}
|
|
|
|
|
P0136R1, DR1573, DR1645, DR1715, DR1736, DR1903, DR1941, DR1959, DR1991:
Replace inheriting constructors implementation with new approach, voted into
C++ last year as a DR against C++11.
Instead of synthesizing a set of derived class constructors for each inherited
base class constructor, we make the constructors of the base class visible to
constructor lookup in the derived class, using the normal rules for
using-declarations.
For constructors, UsingShadowDecl now has a ConstructorUsingShadowDecl derived
class that tracks the requisite additional information. We create shadow
constructors (not found by name lookup) in the derived class to model the
actual initialization, and have a new expression node,
CXXInheritedCtorInitExpr, to model the initialization of a base class from such
a constructor. (This initialization is special because it performs real perfect
forwarding of arguments.)
In cases where argument forwarding is not possible (for inalloca calls,
variadic calls, and calls with callee parameter cleanup), the shadow inheriting
constructor is not emitted and instead we directly emit the initialization code
into the caller of the inherited constructor.
Note that this new model is not perfectly compatible with the old model in some
corner cases. In particular:
* if B inherits a private constructor from A, and C uses that constructor to
construct a B, then we previously required that A befriends B and B
befriends C, but the new rules require A to befriend C directly, and
* if a derived class has its own constructors (and so its implicit default
constructor is suppressed), it may still inherit a default constructor from
a base class
llvm-svn: 274049
2016-06-29 03:03:57 +08:00
|
|
|
case Expr::CXXInheritedCtorInitExprClass:
|
|
|
|
return canCalleeThrow(*this, E,
|
|
|
|
cast<CXXInheritedCtorInitExpr>(E)->getConstructor());
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::LambdaExprClass: {
|
|
|
|
const LambdaExpr *Lambda = cast<LambdaExpr>(E);
|
|
|
|
CanThrowResult CT = CT_Cannot;
|
2015-07-18 02:21:37 +08:00
|
|
|
for (LambdaExpr::const_capture_init_iterator
|
|
|
|
Cap = Lambda->capture_init_begin(),
|
|
|
|
CapEnd = Lambda->capture_init_end();
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
Cap != CapEnd; ++Cap)
|
|
|
|
CT = mergeCanThrow(CT, canThrow(*Cap));
|
|
|
|
return CT;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXNewExprClass: {
|
|
|
|
CanThrowResult CT;
|
|
|
|
if (E->isTypeDependent())
|
|
|
|
CT = CT_Dependent;
|
|
|
|
else
|
|
|
|
CT = canCalleeThrow(*this, E, cast<CXXNewExpr>(E)->getOperatorNew());
|
|
|
|
if (CT == CT_Can)
|
|
|
|
return CT;
|
|
|
|
return mergeCanThrow(CT, canSubExprsThrow(*this, E));
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXDeleteExprClass: {
|
|
|
|
CanThrowResult CT;
|
|
|
|
QualType DTy = cast<CXXDeleteExpr>(E)->getDestroyedType();
|
|
|
|
if (DTy.isNull() || DTy->isDependentType()) {
|
|
|
|
CT = CT_Dependent;
|
|
|
|
} else {
|
|
|
|
CT = canCalleeThrow(*this, E,
|
|
|
|
cast<CXXDeleteExpr>(E)->getOperatorDelete());
|
|
|
|
if (const RecordType *RT = DTy->getAs<RecordType>()) {
|
|
|
|
const CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl());
|
2013-06-25 09:24:22 +08:00
|
|
|
const CXXDestructorDecl *DD = RD->getDestructor();
|
|
|
|
if (DD)
|
|
|
|
CT = mergeCanThrow(CT, canCalleeThrow(*this, E, DD));
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
}
|
|
|
|
if (CT == CT_Can)
|
|
|
|
return CT;
|
|
|
|
}
|
|
|
|
return mergeCanThrow(CT, canSubExprsThrow(*this, E));
|
|
|
|
}
|
|
|
|
|
|
|
|
case Expr::CXXBindTemporaryExprClass: {
|
|
|
|
// The bound temporary has to be destroyed again, which might throw.
|
|
|
|
CanThrowResult CT = canCalleeThrow(*this, E,
|
|
|
|
cast<CXXBindTemporaryExpr>(E)->getTemporary()->getDestructor());
|
|
|
|
if (CT == CT_Can)
|
|
|
|
return CT;
|
|
|
|
return mergeCanThrow(CT, canSubExprsThrow(*this, E));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjC message sends are like function calls, but never have exception
|
|
|
|
// specs.
|
|
|
|
case Expr::ObjCMessageExprClass:
|
|
|
|
case Expr::ObjCPropertyRefExprClass:
|
|
|
|
case Expr::ObjCSubscriptRefExprClass:
|
|
|
|
return CT_Can;
|
|
|
|
|
|
|
|
// All the ObjC literals that are implemented as calls are
|
|
|
|
// potentially throwing unless we decide to close off that
|
|
|
|
// possibility.
|
|
|
|
case Expr::ObjCArrayLiteralClass:
|
|
|
|
case Expr::ObjCDictionaryLiteralClass:
|
2012-04-19 08:25:12 +08:00
|
|
|
case Expr::ObjCBoxedExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
return CT_Can;
|
|
|
|
|
|
|
|
// Many other things have subexpressions, so we have to test those.
|
|
|
|
// Some are simple:
|
2015-10-27 14:02:45 +08:00
|
|
|
case Expr::CoawaitExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::ConditionalOperatorClass:
|
|
|
|
case Expr::CompoundLiteralExprClass:
|
2015-10-27 14:02:45 +08:00
|
|
|
case Expr::CoyieldExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::CXXConstCastExprClass:
|
|
|
|
case Expr::CXXReinterpretCastExprClass:
|
2013-06-13 06:31:48 +08:00
|
|
|
case Expr::CXXStdInitializerListExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::DesignatedInitExprClass:
|
2015-06-10 08:27:52 +08:00
|
|
|
case Expr::DesignatedInitUpdateExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::ExprWithCleanupsClass:
|
|
|
|
case Expr::ExtVectorElementExprClass:
|
|
|
|
case Expr::InitListExprClass:
|
|
|
|
case Expr::MemberExprClass:
|
|
|
|
case Expr::ObjCIsaExprClass:
|
|
|
|
case Expr::ObjCIvarRefExprClass:
|
|
|
|
case Expr::ParenExprClass:
|
|
|
|
case Expr::ParenListExprClass:
|
|
|
|
case Expr::ShuffleVectorExprClass:
|
2013-09-18 11:29:45 +08:00
|
|
|
case Expr::ConvertVectorExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::VAArgExprClass:
|
|
|
|
return canSubExprsThrow(*this, E);
|
|
|
|
|
|
|
|
// Some might be dependent for other reasons.
|
|
|
|
case Expr::ArraySubscriptExprClass:
|
2015-08-25 22:24:04 +08:00
|
|
|
case Expr::OMPArraySectionExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::BinaryOperatorClass:
|
|
|
|
case Expr::CompoundAssignOperatorClass:
|
|
|
|
case Expr::CStyleCastExprClass:
|
|
|
|
case Expr::CXXStaticCastExprClass:
|
|
|
|
case Expr::CXXFunctionalCastExprClass:
|
|
|
|
case Expr::ImplicitCastExprClass:
|
|
|
|
case Expr::MaterializeTemporaryExprClass:
|
|
|
|
case Expr::UnaryOperatorClass: {
|
|
|
|
CanThrowResult CT = E->isTypeDependent() ? CT_Dependent : CT_Cannot;
|
|
|
|
return mergeCanThrow(CT, canSubExprsThrow(*this, E));
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We should handle StmtExpr, but that opens a MASSIVE can of worms.
|
|
|
|
case Expr::StmtExprClass:
|
|
|
|
return CT_Can;
|
|
|
|
|
2013-04-21 06:23:05 +08:00
|
|
|
case Expr::CXXDefaultArgExprClass:
|
|
|
|
return canThrow(cast<CXXDefaultArgExpr>(E)->getExpr());
|
|
|
|
|
|
|
|
case Expr::CXXDefaultInitExprClass:
|
|
|
|
return canThrow(cast<CXXDefaultInitExpr>(E)->getExpr());
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::ChooseExprClass:
|
|
|
|
if (E->isTypeDependent() || E->isValueDependent())
|
|
|
|
return CT_Dependent;
|
2013-07-20 08:40:58 +08:00
|
|
|
return canThrow(cast<ChooseExpr>(E)->getChosenSubExpr());
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
|
|
|
|
case Expr::GenericSelectionExprClass:
|
|
|
|
if (cast<GenericSelectionExpr>(E)->isResultDependent())
|
|
|
|
return CT_Dependent;
|
|
|
|
return canThrow(cast<GenericSelectionExpr>(E)->getResultExpr());
|
|
|
|
|
|
|
|
// Some expressions are always dependent.
|
|
|
|
case Expr::CXXDependentScopeMemberExprClass:
|
|
|
|
case Expr::CXXUnresolvedConstructExprClass:
|
|
|
|
case Expr::DependentScopeDeclRefExprClass:
|
2014-11-08 13:07:16 +08:00
|
|
|
case Expr::CXXFoldExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
return CT_Dependent;
|
|
|
|
|
|
|
|
case Expr::AsTypeExprClass:
|
|
|
|
case Expr::BinaryConditionalOperatorClass:
|
|
|
|
case Expr::BlockExprClass:
|
|
|
|
case Expr::CUDAKernelCallExprClass:
|
|
|
|
case Expr::DeclRefExprClass:
|
|
|
|
case Expr::ObjCBridgedCastExprClass:
|
|
|
|
case Expr::ObjCIndirectCopyRestoreExprClass:
|
|
|
|
case Expr::ObjCProtocolExprClass:
|
|
|
|
case Expr::ObjCSelectorExprClass:
|
2016-07-16 08:35:23 +08:00
|
|
|
case Expr::ObjCAvailabilityCheckExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::OffsetOfExprClass:
|
|
|
|
case Expr::PackExpansionExprClass:
|
|
|
|
case Expr::PseudoObjectExprClass:
|
|
|
|
case Expr::SubstNonTypeTemplateParmExprClass:
|
|
|
|
case Expr::SubstNonTypeTemplateParmPackExprClass:
|
2012-09-12 08:56:43 +08:00
|
|
|
case Expr::FunctionParmPackExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::UnaryExprOrTypeTraitExprClass:
|
|
|
|
case Expr::UnresolvedLookupExprClass:
|
|
|
|
case Expr::UnresolvedMemberExprClass:
|
2014-10-28 02:07:20 +08:00
|
|
|
case Expr::TypoExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
// FIXME: Can any of the above throw? If so, when?
|
|
|
|
return CT_Cannot;
|
|
|
|
|
|
|
|
case Expr::AddrLabelExprClass:
|
|
|
|
case Expr::ArrayTypeTraitExprClass:
|
|
|
|
case Expr::AtomicExprClass:
|
|
|
|
case Expr::TypeTraitExprClass:
|
|
|
|
case Expr::CXXBoolLiteralExprClass:
|
|
|
|
case Expr::CXXNoexceptExprClass:
|
|
|
|
case Expr::CXXNullPtrLiteralExprClass:
|
|
|
|
case Expr::CXXPseudoDestructorExprClass:
|
|
|
|
case Expr::CXXScalarValueInitExprClass:
|
|
|
|
case Expr::CXXThisExprClass:
|
|
|
|
case Expr::CXXUuidofExprClass:
|
|
|
|
case Expr::CharacterLiteralClass:
|
|
|
|
case Expr::ExpressionTraitExprClass:
|
|
|
|
case Expr::FloatingLiteralClass:
|
|
|
|
case Expr::GNUNullExprClass:
|
|
|
|
case Expr::ImaginaryLiteralClass:
|
|
|
|
case Expr::ImplicitValueInitExprClass:
|
|
|
|
case Expr::IntegerLiteralClass:
|
2015-06-10 08:27:52 +08:00
|
|
|
case Expr::NoInitExprClass:
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
case Expr::ObjCEncodeExprClass:
|
|
|
|
case Expr::ObjCStringLiteralClass:
|
|
|
|
case Expr::ObjCBoolLiteralExprClass:
|
|
|
|
case Expr::OpaqueValueExprClass:
|
|
|
|
case Expr::PredefinedExprClass:
|
|
|
|
case Expr::SizeOfPackExprClass:
|
|
|
|
case Expr::StringLiteralClass:
|
|
|
|
// These expressions can never throw.
|
|
|
|
return CT_Cannot;
|
|
|
|
|
2013-04-16 15:28:30 +08:00
|
|
|
case Expr::MSPropertyRefExprClass:
|
2015-11-25 20:01:00 +08:00
|
|
|
case Expr::MSPropertySubscriptExprClass:
|
2013-04-16 15:28:30 +08:00
|
|
|
llvm_unreachable("Invalid class for expression");
|
|
|
|
|
Implement DR1330 in C++11 mode, to support libstdc++4.7 which uses it.
We have a new flavor of exception specification, EST_Uninstantiated. A function
type with this exception specification carries a pointer to a FunctionDecl, and
the exception specification for that FunctionDecl is instantiated (if needed)
and used in the place of the function type's exception specification.
When a function template declaration with a non-trivial exception specification
is instantiated, the specialization's exception specification is set to this
new 'uninstantiated' kind rather than being instantiated immediately.
Expr::CanThrow has migrated onto Sema, so it can instantiate exception specs
on-demand. Also, any odr-use of a function triggers the instantiation of its
exception specification (the exception specification could be needed by IRGen).
In passing, fix two places where a DeclRefExpr was created but the corresponding
function was not actually marked odr-used. We used to get away with this, but
don't any more.
Also fix a bug where instantiating an exception specification which refers to
function parameters resulted in a crash. We still have the same bug in default
arguments, which I'll be looking into next.
This, plus a tiny patch to fix libstdc++'s common_type, is enough for clang to
parse (and, in very limited testing, support) all of libstdc++4.7's standard
headers.
llvm-svn: 154886
2012-04-17 08:58:00 +08:00
|
|
|
#define STMT(CLASS, PARENT) case Expr::CLASS##Class:
|
|
|
|
#define STMT_RANGE(Base, First, Last)
|
|
|
|
#define LAST_STMT_RANGE(BASE, FIRST, LAST)
|
|
|
|
#define EXPR(CLASS, PARENT)
|
|
|
|
#define ABSTRACT_STMT(STMT)
|
|
|
|
#include "clang/AST/StmtNodes.inc"
|
|
|
|
case Expr::NoStmtClass:
|
|
|
|
llvm_unreachable("Invalid class for expression");
|
|
|
|
}
|
|
|
|
llvm_unreachable("Bogus StmtClass");
|
|
|
|
}
|
|
|
|
|
2009-10-11 17:03:14 +08:00
|
|
|
} // end namespace clang
|