[cfe-commits] r74118 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/Sema/SemaType.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp

Douglas Gregor dgregor at apple.com
Thu Jun 25 22:22:46 PDT 2009


>
> /// getDecltypeType -  Unlike many "get<Type>" functions, we don't  
> unique
> /// DecltypeType AST's. The only motivation to unique these nodes  
> would be
> /// memory savings. Since decltype(t) is fairly uncommon, space  
> shouldn't be
> /// an issue. This doesn't effect the type checker, since it operates
> /// on canonical type's (which are always unique).

This is FIXME worthy, because we will eventually need to canonicalize  
dependent decltype types for catching redeclarations of class template  
partial specializations and function templates, e.g.,

   template<class T> void f(T, decltype(T() + T()) a);

   template<class U> void f(U, decltype(U() + U()) a);

But, we don't have the ability to canonicalize expressions yet.

   - Doug

> QualType ASTContext::getDecltypeType(Expr *e) {
> -  // FIXME: Use the right type here!
> -  QualType Canonical = getCanonicalType(e->getType());
> -  DecltypeType *dt = new (*this, 8) DecltypeType(e, Canonical);
> +  QualType T = getDecltypeForExpr(e, *this);
> +  DecltypeType *dt = new (*this, 8) DecltypeType(e, getCanonicalType 
> (T));
>   Types.push_back(dt);
>   return QualType(dt, 0);
> }
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=74118&r1=74117&r2=74118&view=diff
>
> === 
> === 
> === 
> =====================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Wed Jun 24 16:24:56 2009
> @@ -240,10 +240,7 @@
>     Expr *E = static_cast<Expr *>(DS.getTypeRep());
>     assert(E && "Didn't get an expression for decltype?");
>     // TypeQuals handled by caller.
> -
> -    // FIXME: Use the right type!
> -    Result = Context.IntTy;
> -    isInvalid = true;
> +    Result = Context.getDecltypeType(E);
>     break;
>   }
>
>
> Added: cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/ 
> p4-cxx0x.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4-cxx0x.cpp?rev=74118&view=auto
>
> === 
> === 
> === 
> =====================================================================
> --- cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4- 
> cxx0x.cpp (added)
> +++ cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.type.simple/p4- 
> cxx0x.cpp Wed Jun 24 16:24:56 2009
> @@ -0,0 +1,21 @@
> +// RUN: clang-cc -fsyntax-only -std=c++0x -verify %s
> +
> +template<typename T, typename U>
> +struct is_same {
> +  static const bool value = false;
> +};
> +
> +template<typename T>
> +struct is_same<T, T> {
> +  static const bool value = true;
> +};
> +
> +const int&& foo();
> +int i;
> +struct A { double x; };
> +const A* a = new A();
> +
> +static_assert(is_same<decltype(foo()), const int&&>::value, "");
> +static_assert(is_same<decltype(i), int>::value, "");
> +static_assert(is_same<decltype(a->x), double>::value, "");
> +static_assert(is_same<decltype((a->x)), const double&>::value, "");
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list