0

I wrote a global static lambda like the following:

 static auto x = [] (const std::string& y){
   VLOG(3) <<" y:" <<y; 
 };

it is giving me this error on VLOG statement.:

 statement-expressions are not allowed outside functions nor in template-argument lists
Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
rovy
  • 2,481
  • 5
  • 18
  • 26

1 Answers1

1

This is the result of a decision made to leave room for optimizations. The relevant bug report is here in an attempt to reopen the discussion, and specifically mentions your type of use case. Compiling without optimizations should work, though I know that's a lame suggestion. The problem is with the lambda being at global scope, so any solution that brings it into a function should be good.

Ryan Haining
  • 35,360
  • 15
  • 114
  • 174