Bug #2717 include/my_global.h mis-defines __attribute__
Submitted: 11 Feb 2004 13:55 Modified: 5 Oct 2006 15:01
Reporter: Dean Ellis Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:3.23 OS:
Assigned to: Jim Winstead CPU Architecture:Any
Tags: __attribute__, gcc

[11 Feb 2004 13:55] Dean Ellis
Description:
include/my_global.h includes the following:

#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__) || __GNUC__ == 2 && __GNUC_MINOR__ < 8)
#define __attribute__(A)
#endif

Which can cause problems if it is included to early in other coded that includes my_global.h. The GCC bug database includes a reference to this as well:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13527

How to repeat:
n/a

Suggested fix:
n/a
[12 Feb 2004 8:12] Sergei Golubchik
looks like the problem here is "defined(__cplusplus)"
[11 Jun 2004 19:58] Hartmut Holzgraefe
Some uses of __attribute__ that are valid for gcc are not yet supported by g++.
It seems that __attribute__ is defined as an empty macro in my_globals.h to prevent error messages when a C source file or headerusing these __attributes__s is used in a C++ context. 

One of the __attributes__s not supported by g++ prior to version 3.4.0 is
__attribute__((unused)) for function parameters.

What confuses me a bit is that this is actually *used* in our C++ code although
support for it was only added in 3.4.0 released less than two month ago.

I assume that it was added by someone not aware of g++ not supporting it for parameters yet and the definition in my_globals.h did just hide that fact so that nobody noticed ...

So unless someone wants to clean up all existing code i suggest to change the condition in my_globals to

#if !defined(__attribute__) && (!defined(__GNUC__)  || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || (defined(__cplusplus) && __GNUC__ <= 3 && __GNUC_MINOR__ < 4))
#define __attribute__(A)
#endif

a cleaner approach might be to #define something like:

#if defined(__cplusplus) && __GNUC__ <= 3 && __GNUC_MINOR__ < 4
#define __unused_parameter__
#else
#define __unused_parameter__ __attribute__((unused))
#endif 

and changing all uses of __attribute__((unused)) in parameter lists
to __unused__parameter__. (Note: i did not test if this really works)

(Note: i did not really test if g++ 3.4.0 does support the unused 
attribute on parameters, i only read it in the bugzilla bug logs)
[15 Mar 2006 19:08] Mark Callaghan
The ifdef check needs to be even more complicated to evaluate to true for gcc 2 for those of us who are still using 2.95

#if !defined(__attribute__) && \
     (!defined(__GNUC__)  || \
     (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || \
     (defined(__cplusplus) && \
       (__GNUC__ < 3 || __GNUC__ = 3 && __GNUC_MINOR__ < 4)))
#define __attribute__(A)
#endif
[15 Mar 2006 20:02] Mark Callaghan
Fix typo ('=' --> '==')

#if !defined(__attribute__) && \
     (!defined(__GNUC__)  || \
     (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || \
     (defined(__cplusplus) && \
       (__GNUC__ < 3 || __GNUC__ == 3 && __GNUC_MINOR__ < 4)))
#define __attribute__(A)
#endif
[4 Aug 2006 15:01] Sergei Golubchik
http://lists.mysql.com/internals/33741
[11 Aug 2006 20:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/10321

ChangeSet@1.2538, 2006-08-11 13:43:33-07:00, jimw@rama.(none) +14 -0
  Bug #2717: include/my_global.h mis-defines __attribute__
  
    Fix when __attribute__() is stubbed out, add ATTRIBUTE_FORMAT() for specifying
    __attribute__((format(...))) safely, make more use of the format attribute,
    and fix some of the warnings that this turns up.
[17 Aug 2006 19:21] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/10600

ChangeSet@1.2538, 2006-08-17 12:25:40-07:00, jimw@rama.(none) +14 -0
  Bug #2717: include/my_global.h mis-defines __attribute__
  
    Fix when __attribute__() is stubbed out, add ATTRIBUTE_FORMAT() for specifying
    __attribute__((format(...))) safely, make more use of the format attribute,
    and fix some of the warnings that this turns up (plus a bonus unrelated one).
[29 Sep 2006 3:38] Jim Winstead
Pushed to 4.1-maint, 5.0-maint, and 5.1-maint.

I did not fix the additional warnings this turns up in the 5.0 and 5.1 trees. They should get cleaned up as part of the work on Bug #22100.
[29 Sep 2006 18:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/12860

ChangeSet@1.2555, 2006-09-29 11:24:57-07:00, jimw@rama.(none) +1 -0
  Disable __attribute__ entirely on g++ < 3.4. (Bug #2717)
[29 Sep 2006 20:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/12872

ChangeSet@1.2555, 2006-09-29 14:04:26-07:00, jimw@rama.(none) +1 -0
  Disable __attribute__ entirely on g++ < 3.4. (Bug #2717)
[30 Sep 2006 3:18] Jim Winstead
The second patch to fix the definition of __attribute__ for g++ < 3.4 has also been pushed into the three -maint trees.
[3 Oct 2006 20:00] Chad MILLER
Available in 5.0.26.
[3 Oct 2006 20:03] Chad MILLER
Available in 5.0.26.
[3 Oct 2006 20:11] Chad MILLER
Available in 5.1.12-beta.
[4 Oct 2006 13:58] Chad MILLER
Available in 4.1.22.
[5 Oct 2006 15:01] Paul DuBois
Noted in 4.1.22, 5.0.26, 5.1.12 changelogs.

Incorporated some portability fixes into the definition of
__attribute__ in my_global.h.