Submitted by: Bill Wendling

Reviewed by: Chris Lattner

- Disallow references to references, pointers to references, or arrays of
  references.

llvm-svn: 39569
This commit is contained in:
Bill Wendling 2007-06-02 23:30:50 +00:00
parent db4f06ed2c
commit 8c06ef8851
1 changed files with 20 additions and 2 deletions

View File

@ -116,12 +116,25 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
switch (DeclType.Kind) {
default: assert(0 && "Unknown decltype!");
case DeclaratorChunk::Pointer:
T = Context.getPointerType(T);
if (isa<ReferenceType>(T.getCanonicalType().getTypePtr())) {
// C++ 8.3.2p4: There shall be no ... pointers to references ...
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_pointer_to_reference,
D.getIdentifier()->getName());
return QualType();
}
// Apply the pointer typequals to the pointer object.
T = T.getQualifiedType(DeclType.Ptr.TypeQuals);
T = Context.getPointerType(T).getQualifiedType(DeclType.Ptr.TypeQuals);
break;
case DeclaratorChunk::Reference:
if (isa<ReferenceType>(T.getCanonicalType().getTypePtr())) {
// C++ 8.3.2p4: There shall be no references to references ...
Diag(D.getIdentifierLoc(),
diag::err_illegal_decl_reference_to_reference,
D.getIdentifier()->getName());
return QualType();
}
T = Context.getReferenceType(T);
break;
case DeclaratorChunk::Array: {
@ -146,6 +159,11 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) {
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
D.getIdentifier()->getName());
return QualType();
} else if (isa<ReferenceType>(CanonicalT)) {
// C++ 8.3.2p4: There shall be no ... arrays of references ...
Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_references,
D.getIdentifier()->getName());
return QualType();
} else if (RecordType *EltTy = dyn_cast<RecordType>(CanonicalT)) {
// If the element type is a struct or union that contains a variadic
// array, reject it: C99 6.7.2.1p2.