[cfe-commits] r105463 - in /cfe/trunk/lib/Sema: SemaDecl.cpp SemaDeclCXX.cpp
John McCall
rjmccall at apple.com
Fri Jun 4 01:34:12 PDT 2010
Author: rjmccall
Date: Fri Jun 4 03:34:12 2010
New Revision: 105463
URL: http://llvm.org/viewvc/llvm-project?rev=105463&view=rev
Log:
Delay checking for mutable const fields until we're checking the field.
Allows this check to work properly for instantiated fields and removes
an unnecessary GetTypeForDeclarator call.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=105463&r1=105462&r2=105463&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Jun 4 03:34:12 2010
@@ -5740,6 +5740,24 @@
ZeroWidth = false;
}
+ // Check that 'mutable' is consistent with the type of the declaration.
+ if (!InvalidDecl && Mutable) {
+ unsigned DiagID = 0;
+ if (T->isReferenceType())
+ DiagID = diag::err_mutable_reference;
+ else if (T.isConstQualified())
+ DiagID = diag::err_mutable_const;
+
+ if (DiagID) {
+ SourceLocation ErrLoc = Loc;
+ if (D && D->getDeclSpec().getStorageClassSpecLoc().isValid())
+ ErrLoc = D->getDeclSpec().getStorageClassSpecLoc();
+ Diag(ErrLoc, DiagID);
+ Mutable = false;
+ InvalidDecl = true;
+ }
+ }
+
FieldDecl *NewFD = FieldDecl::Create(Context, Record, Loc, II, T, TInfo,
BitWidth, Mutable);
if (InvalidDecl)
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=105463&r1=105462&r2=105463&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Jun 4 03:34:12 2010
@@ -886,10 +886,18 @@
Expr *Init = static_cast<Expr*>(InitExpr);
SourceLocation Loc = D.getIdentifierLoc();
- bool isFunc = D.isFunctionDeclarator();
-
+ assert(isa<CXXRecordDecl>(CurContext));
assert(!DS.isFriendSpecified());
+ bool isFunc = false;
+ if (D.isFunctionDeclarator())
+ isFunc = true;
+ else if (D.getNumTypeObjects() == 0 &&
+ D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_typename) {
+ QualType TDType = GetTypeFromParser(DS.getTypeRep());
+ isFunc = TDType->isFunctionType();
+ }
+
// C++ 9.2p6: A member shall not be declared to have automatic storage
// duration (auto, register) or with the extern storage-class-specifier.
// C++ 7.1.1p8: The mutable specifier can be applied only to names of class
@@ -911,22 +919,6 @@
// FIXME: It would be nicer if the keyword was ignored only for this
// declarator. Otherwise we could get follow-up errors.
D.getMutableDeclSpec().ClearStorageClassSpecs();
- } else {
- QualType T = GetTypeForDeclarator(D, S);
- diag::kind err = static_cast<diag::kind>(0);
- if (T->isReferenceType())
- err = diag::err_mutable_reference;
- else if (T.isConstQualified())
- err = diag::err_mutable_const;
- if (err != 0) {
- if (DS.getStorageClassSpecLoc().isValid())
- Diag(DS.getStorageClassSpecLoc(), err);
- else
- Diag(DS.getThreadSpecLoc(), err);
- // FIXME: It would be nicer if the keyword was ignored only for this
- // declarator. Otherwise we could get follow-up errors.
- D.getMutableDeclSpec().ClearStorageClassSpecs();
- }
}
break;
default:
@@ -938,18 +930,6 @@
D.getMutableDeclSpec().ClearStorageClassSpecs();
}
- if (!isFunc &&
- D.getDeclSpec().getTypeSpecType() == DeclSpec::TST_typename &&
- D.getNumTypeObjects() == 0) {
- // Check also for this case:
- //
- // typedef int f();
- // f a;
- //
- QualType TDType = GetTypeFromParser(DS.getTypeRep());
- isFunc = TDType->isFunctionType();
- }
-
bool isInstField = ((DS.getStorageClassSpec() == DeclSpec::SCS_unspecified ||
DS.getStorageClassSpec() == DeclSpec::SCS_mutable) &&
!isFunc);
More information about the cfe-commits
mailing list