[cfe-commits] r71689 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/temp_explicit.cpp test/SemaTemplate/temp_explicit_cxx0x.cpp

Eli Friedman eli.friedman at gmail.com
Wed May 13 12:44:51 PDT 2009


On Wed, May 13, 2009 at 11:28 AM, Douglas Gregor <dgregor at apple.com> wrote:
> --- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed May 13 13:28:20 2009
> @@ -247,10 +247,26 @@
>   // Build a temporary integer literal to specify the size for
>   // BuildArrayType. Since we have already checked the size as part of
>   // creating the dependent array type in the first place, we know
> -  // there aren't any errors.
> -  // FIXME: Is IntTy big enough? Maybe not, but LongLongTy causes
> -  // problems that I have yet to investigate.
> -  IntegerLiteral ArraySize(T->getSize(), SemaRef.Context.IntTy, Loc);
> +  // there aren't any errors. However, we do need to determine what
> +  // C++ type to give the size expression.
> +  llvm::APInt Size = T->getSize();
> +  QualType Types[] = {
> +    SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
> +    SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
> +    SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
> +  };
> +  const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
> +  QualType SizeType;
> +  for (unsigned I = 0; I != NumTypes; ++I)
> +    if (Size.getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
> +      SizeType = Types[I];
> +      break;
> +    }
> +
> +  if (SizeType.isNull())
> +    SizeType = SemaRef.Context.getFixedWidthIntType(Size.getBitWidth(), false);
> +
> +  IntegerLiteral ArraySize(Size, SizeType, Loc);
>   return SemaRef.BuildArrayType(ElementType, T->getSizeModifier(),
>                                 &ArraySize, T->getIndexTypeQualifier(),
>                                 Loc, Entity);

Would there be an issue with just using getFixedWidthIntType
unconditionally?  The type of the integer literal doesn't actually
matter.

-Eli




More information about the cfe-commits mailing list