[cfe-commits] [PATCH][MS] - operator __uuidof implementation part 1

Douglas Gregor dgregor at apple.com
Tue Sep 7 13:01:00 PDT 2010


On Sep 5, 2010, at 1:38 PM, Francois Pichet wrote:

> Hi,
> 
> Updated patch attached.
> 
> 
>> Is __uuidof only available in C++ mode, or does MSVC also allow it in C mode?
> 
> yes __uuidof is only available in C++ mode.
> 
>> Is there anything dynamci about __uuidof? In other words, is the result of __uuidof always a constant, or can it involve run-time computation? If it does not involve run-time computation, then you can use the Unevaluated context rather than the PotentiallyPotentiallyEvaluated context.
> 
> No there is nothing dynamic about __uuidof. It is always resolved at
> compile time. So I changed the code to use the Unevaluated context.
> Not sure exactly why, I am still learning clang internal design.

It's because the expression inside the __uuidof operator never actually generates any code, just like the expression inside the sizeof operator doesn't generate any code. Marking it as "Unevaluated" indicates that this is the case and, for example, suppressed the instantiation of function templates that are called inside the __uuidof expression.

One more comment...

Index: lib/Parse/ParseExprCXX.cpp
===================================================================
--- lib/Parse/ParseExprCXX.cpp	(revision 113112)
+++ lib/Parse/ParseExprCXX.cpp	(working copy)
@@ -534,6 +534,54 @@
   return move(Result);
 }
 
+/// ParseCXXUuidof - This handles the Microsoft C++ __uuidof expression.
+///
+///         '__uuidof' '(' expression ')'
+///         '__uuidof' '(' type-id ')'
+///
+ExprResult Parser::ParseCXXUuidof() {
+  assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!");
+
+  SourceLocation OpLoc = ConsumeToken();
+  SourceLocation LParenLoc = Tok.getLocation();
+  SourceLocation RParenLoc;
+
+  // __uuidof expressions are always parenthesized.
+  if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
+      "__uuidof"))
+    return ExprError();
+
+  ExprResult Result;
+
+  if (isTypeIdInParens()) {
+    TypeResult Ty = ParseTypeName();
+
+    // Match the ')'.
+    MatchRHSPunctuation(tok::r_paren, LParenLoc);
+
+    if (Ty.isInvalid())
+      return ExprError();
+
+    Result = Actions.ActOnCXXUuidof(OpLoc, LParenLoc, /*isType=*/true,
+                                    Ty.get().getAsOpaquePtr(), RParenLoc);

RParenLoc is never set to a location (other than its default, empty state), either on this path or on the __uuidof(expression) path.

With that fix, feel free to commit!

	- Doug



More information about the cfe-commits mailing list