Skip to content

Commit 0066db9

Browse files
committed
The result of the Microsoft __uuidof operator must be considered a global lvalue during constant expression evaluation.
Otherwise we would get this error in C++11 mode (because of a recent change): error: non-type template argument of type 'const _GUID *' is not a constant expression For code like: template <const GUID* g = &__uuidof(struct_with_uuid)> class COM_CLASS { }; llvm-svn: 154790
1 parent 7f1ff60 commit 0066db9

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ static bool IsGlobalLValue(APValue::LValueBase B) {
934934
case Expr::ObjCStringLiteralClass:
935935
case Expr::ObjCEncodeExprClass:
936936
case Expr::CXXTypeidExprClass:
937+
case Expr::CXXUuidofExprClass:
937938
return true;
938939
case Expr::CallExprClass:
939940
return IsStringLiteralCall(cast<CallExpr>(E));
@@ -2872,6 +2873,7 @@ class LValueExprEvaluator
28722873
bool VisitStringLiteral(const StringLiteral *E) { return Success(E); }
28732874
bool VisitObjCEncodeExpr(const ObjCEncodeExpr *E) { return Success(E); }
28742875
bool VisitCXXTypeidExpr(const CXXTypeidExpr *E);
2876+
bool VisitCXXUuidofExpr(const CXXUuidofExpr *E);
28752877
bool VisitArraySubscriptExpr(const ArraySubscriptExpr *E);
28762878
bool VisitUnaryDeref(const UnaryOperator *E);
28772879
bool VisitUnaryReal(const UnaryOperator *E);
@@ -2977,6 +2979,10 @@ bool LValueExprEvaluator::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
29772979
return Success(E);
29782980
}
29792981

2982+
bool LValueExprEvaluator::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
2983+
return Success(E);
2984+
}
2985+
29802986
bool LValueExprEvaluator::VisitMemberExpr(const MemberExpr *E) {
29812987
// Handle static data members.
29822988
if (const VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) {

clang/test/Parser/MicrosoftExtensions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fdelayed-template-parsing
1+
// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fdelayed-template-parsing
22

33
/* Microsoft attribute tests */
44
[repeatable][source_annotation_attribute( Parameter|ReturnValue )]
@@ -103,7 +103,7 @@ typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2;
103103

104104
template <class T, const GUID& g>
105105
class COM_CLASS_TEMPLATE_REF { };
106-
typedef COM_CLASS_TEMPLATE<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF;
106+
typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF;
107107

108108
struct late_defined_uuid;
109109
template<typename T>

0 commit comments

Comments
 (0)