What is the One-Definition Rule?

The truth is in the standard (3.2 One definition rule) : No translation unit shall contain more than one definition of any variable, function, class type, enumeration type or template. […] Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required. The definition … Read more

Why are const ints (or shorts) captured implicitly in lambdas? [duplicate]

Lambda’s scope can implicitly capture variables within its reaching scope. Your variables are in the reaching scope, since they are local to the (main) function that defines the lambda. However, there are certain criteria in which variables can be captured via this mechanism, as mentioned in [expr.prim.lambda]/12: A lambda-expression with an associated capture-default that does … Read more

Do distinct functions have distinct addresses?

It looks like defect report 1400: Function pointer equality deals with this issue and seems to me to say that it is okay to do this optimization but as comments indicate, there is disagreement. It says (emphasis mine): According to 5.10 [expr.eq] paragraph 2, two function pointers only compare equal if they point to the … Read more

Can using a lambda in header files violate the ODR?

This boils down to whether or not a lambda’s type differs across translation units. If it does, it may affect template argument deduction and potentially cause different functions to be called – in what are meant to be consistent definitions. That would violate the ODR (see below). However, that isn’t intended. In fact, this problem … Read more

What does it mean to “ODR-use” something?

It’s just an arbitrary definition, used by the standard to specify when you must provide a definition for an entity (as opposed to just a declaration). The standard doesn’t say just “used”, because this can be interpreted diversely depending on context. And some ODR-use doesn’t really correspond to what one would normally associate with “use”; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)