[cfe-commits] r113663 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/SemaCXX/class.cpp test/SemaTemplate/instantiate-static-var.cpp
Douglas Gregor
dgregor at apple.com
Fri Sep 10 19:54:27 PDT 2010
On Sep 10, 2010, at 4:21 PM, John McCall wrote:
> Author: rjmccall
> Date: Fri Sep 10 18:21:22 2010
> New Revision: 113663
>
> URL: http://llvm.org/viewvc/llvm-project?rev=113663&view=rev
> Log:
> Support in-class initialization of static const floating-point data members.
This is also PR6384, and has a (now-out-of-date) entry on the compatibility page at
http://clang.llvm.org/compatibility.html#init_static_const
- Doug
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/SemaCXX/class.cpp
> cfe/trunk/test/SemaTemplate/instantiate-static-var.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=113663&r1=113662&r2=113663&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Sep 10 18:21:22 2010
> @@ -619,7 +619,7 @@
> def err_not_integral_type_anon_bitfield : Error<
> "anonymous bit-field has non-integral type %0">;
> def err_member_initialization : Error<
> - "%0 can only be initialized if it is a static const integral data member">;
> + "fields can only be initialized in constructors">;
> def err_member_function_initialization : Error<
> "initializer on function does not look like a pure-specifier">;
> def err_non_virtual_pure : Error<
> @@ -2826,10 +2826,15 @@
> def err_not_direct_base_or_virtual : Error<
> "type %0 is not a direct or virtual base of %1">;
>
> -def err_in_class_initializer_non_integral_type : Error<
> - "in-class initializer has non-integral, non-enumeration type %0">;
> +def err_in_class_initializer_non_const : Error<
> + "non-const static data member must be initialized out of line">;
> +def err_in_class_initializer_bad_type : Error<
> + "static data member of type %0 must be initialized out of line">;
Should out-of-line be hyphenated?
Or, perhaps, "outside of the class"?
> +def ext_in_class_initializer_float_type : ExtWarn<
> + "in-class initializer for static data member of type %0 "
> + "is a C++0x extension">;
> def err_in_class_initializer_non_constant : Error<
> - "in-class initializer is not an integral constant expression">;
> + "in-class initializer is not a constant expression">;
>
> // C++ anonymous unions and GNU anonymous structs/unions
> def ext_anonymous_union : Extension<
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=113663&r1=113662&r2=113663&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 10 18:21:22 2010
> @@ -4115,8 +4115,7 @@
> if (getLangOptions().CPlusPlus &&
> RealDecl->getLexicalDeclContext()->isRecord() &&
> isa<NamedDecl>(RealDecl))
> - Diag(RealDecl->getLocation(), diag::err_member_initialization)
> - << cast<NamedDecl>(RealDecl)->getDeclName();
> + Diag(RealDecl->getLocation(), diag::err_member_initialization);
> else
> Diag(RealDecl->getLocation(), diag::err_illegal_initializer);
> RealDecl->setInvalidDecl();
> @@ -4220,34 +4219,38 @@
> // static const int value = 17;
> // };
>
> - // Attach the initializer
> - VDecl->setInit(Init);
> + // Try to perform the initialization regardless.
> + if (!VDecl->isInvalidDecl()) {
> + InitializationSequence InitSeq(*this, Entity, Kind, &Init, 1);
> + ExprResult Result = InitSeq.Perform(*this, Entity, Kind,
> + MultiExprArg(*this, &Init, 1),
> + &DclT);
> + if (Result.isInvalid()) {
> + VDecl->setInvalidDecl();
> + return;
> + }
> +
> + Init = Result.takeAs<Expr>();
> + }
Much cleaner!
- Doug
More information about the cfe-commits
mailing list