[cfe-commits] r60615 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/Expr.h include/clang/AST/Type.h lib/AST/ASTContext.cpp lib/AST/CFG.cpp lib/AST/Expr.cpp lib/AST/StmtIterator.cpp lib/AST/Type.cpp lib/AST/TypeSerialization.cpp lib/CodeGen/CodeGenTypes.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaStmt.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaType.cpp test/SemaCXX/dependent-types.cpp test/SemaCXX/type-dependent-exprs.cpp

Douglas Gregor dgregor at apple.com
Wed Dec 10 12:44:43 PST 2008


On Dec 6, 2008, at 1:35 PM, Sebastian Redl wrote:

> Douglas Gregor wrote:
>> Author: dgregor
>> Date: Fri Dec  5 17:32:09 2008
>> New Revision: 60615
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=60615&view=rev
>> Log:
>> Introduce basic support for dependent types, type-dependent
>> expressions, and value-dependent expressions. This permits us to  
>> parse
>> some template definitions.
>>
> Yay!
>
>> +/// getDependentSizedArrayType - Returns a non-unique reference to
>> +/// the type for a dependently-sized array of the specified element
>> +/// type. FIXME: We will need these to be uniqued, or at least
>> +/// comparable, at some point.
>>
> Do VLAs have the same FIXME? Why do we need this?

VLAs do have the same FIXME, although I don't think we actually need  
VLAs to be uniqued. With dependently-sized array types, we need them  
to be unique so that we can determine that the types of the arrays  
match in the parameter types of the functions "f" below:

	template<int I, int J> void f(int (&array)[I+J]);
	template<int X, int Y> void f(int (&array)[X+Y]) { ... }

If we don't realize that those canonical types match, we'll think that  
the definition is actually an overload rather than a redeclaration.  
Not good!

>>   // FIXME: What is the ownership of size expressions in VLAs?
>>   VariableArrayType *VAT = cast<VariableArrayType>(AT);
>>   return getVariableArrayType(NewEltTy, VAT->getSizeExpr(),
>> @@ -1246,6 +1282,16 @@
>>     return cast<ArrayType>(getIncompleteArrayType(NewEltTy,
>>                                                   IAT- 
>> >getSizeModifier(),
>>                                                  IAT- 
>> >getIndexTypeQualifier()));
>> +
>> +  // FIXME: What is the ownership of size expressions in
>> +  // dependent-sized array types?
>> +  if (const DependentSizedArrayType *DSAT +        =  
>> dyn_cast<DependentSizedArrayType>(ATy))
>> +    return cast<ArrayType>(
>> +                     getDependentSizedArrayType(NewEltTy,  
>> +                                                DSAT->getSizeExpr(),
>> +                                                DSAT- 
>> >getSizeModifier(),
>> +                                                DSAT- 
>> >getIndexTypeQualifier()));
>>
> VLAs destroy their size expression when they die, so they seem to  
> assume ownership. Why is this still a FIXME?

Hrm, good point. De-FIXME-'d.

>
>>   +// FIXME: Add support for dependent-sized array types in C++?
>> +// Does it even make sense to build a CFG for an uninstantiated  
>> template?
>>
> I'd say no.

That's what I like to hear! Less work for me :)

>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Dec  5 17:32:09 2008
>> @@ -490,7 +490,52 @@
>>   }
>>   // If this reference is not in a block or if the referenced  
>> variable is
>>   // within the block, create a normal DeclRefExpr.
>> -  return new DeclRefExpr(VD, VD->getType().getNonReferenceType(),  
>> Loc);
>> +
>> +  // C++ [temp.dep.expr]p3:
>> +  //   An id-expression is type-dependent if it contains:   +   
>> bool TypeDependent = false;
>>
> I expect the C guys will want this entire block in an if (CPlusPlus).

Yeah, probably. Done.

>
>>    // first, check the condition.
>> -  if (!condT->isScalarType()) { // C99 6.5.15p2
>> -    Diag(cond->getLocStart(),  
>> diag::err_typecheck_cond_expect_scalar) << condT;
>> -    return QualType();
>> +  if (!cond->isTypeDependent()) {
>> +    if (!condT->isScalarType()) { // C99 6.5.15p2
>> +      Diag(cond->getLocStart(),  
>> diag::err_typecheck_cond_expect_scalar) << condT;
>> +      return QualType();
>> +    }
>>   }
>>
> Merge the ifs?

We would just un-merge them later, when we perform the contextual  
conversion to bool for record types.

>
>> Added: cfe/trunk/test/SemaCXX/dependent-types.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/dependent-types.cpp?rev=60615&view=auto
>>
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>> --- cfe/trunk/test/SemaCXX/dependent-types.cpp (added)
>> +++ cfe/trunk/test/SemaCXX/dependent-types.cpp Fri Dec  5 17:32:09  
>> 2008
>>
> I expect we'll get so many template test cases that we should make a  
> SemaTemplate directory to hold those tests.

I was starting to think that it would be great to have SemaCXX's  
directory structure reflect the structure of the standard itself, so  
SemaCXX/temp would be template chapter, SemaCXX/over would be  
overloading, etc. Eventually, we'll have to do something to break  
things up.

> Great work, Doug.

Thanks! (and thanks for the review).

	- Doug



More information about the cfe-commits mailing list