Bug #83077 Make array_elements() type-safe
| Submitted: | 21 Sep 2016 11:19 | Modified: | 27 Sep 2016 15:23 |
|---|---|---|---|
| Reporter: | Steinar Gunderson | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Compiling | Severity: | S3 (Non-critical) |
| Version: | 8.0.1 | OS: | Any |
| Assigned to: | CPU Architecture: | Any |
[27 Sep 2016 15:23]
Paul DuBois
Posted by developer: Fixed in 8.0.1. Code cleanup. No changelog entry needed.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.038 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: array_elements() is a macro defined as #define array_elements(A) ((uint) (sizeof(A)/sizeof(A[0]))) This was the best you could do in the C days, but now in C++11, it's possible to make it type-safe. Specifically, the current version contains some traps where you can inadvertently apply it to a pointer: int foo(int x[13]) // x decays from array to pointer in argument { return array_elements(x); // No error, returns 2! } or an STL container: int bar(const std::vector<int> &x) { return array_elements(x); // No error, returns 6! } How to repeat: N/A Suggested fix: We should use a constexpr template instead. "Effective Modern C++" shows how.