Bug 13527 - __attribute__ ((unused)) ignored
Summary: __attribute__ ((unused)) ignored
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-30 22:34 UTC by Robin Daugherty
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
File With The Warning (337 bytes, text/plain)
2003-12-31 14:45 UTC, Robin Daugherty
Details
File Without The Warning (correct behavior) (339 bytes, text/plain)
2003-12-31 14:50 UTC, Robin Daugherty
Details
MySQL header file (9.81 KB, text/plain)
2003-12-31 15:07 UTC, Robin Daugherty
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Daugherty 2003-12-30 22:34:28 UTC
In a number of seperate files, the ((unused)) attribute went ignored, causing
warnings for these lines:

static char bugs_doc[] __attribute__ ((unused)) = "Robin Daugherty";
static char version[] __attribute__ ((unused)) = "hsmdr 1.0 (2003-APR-29)";

But only if the mysql header files are included first:

// MySQL client headers
#include <mysql/my_global.h>
#include <mysql/my_sys.h>
#include <mysql/m_string.h>
#include <mysql/mysql.h>
#include <mysql/mysql_embed.h>
#include <mysql/errmsg.h>
#include <mysql/my_getopt.h>

Moving this block before the two declarations causes warnings to be issued:

hsmdr.cpp:48: warning: `char bugs_doc[16]' defined but not used
hsmdr.cpp:49: warning: `char version[24]' defined but not used

But these warnings are gone if the declaration is first.
Comment 1 Andrew Pinski 2003-12-30 22:54:27 UTC
Can you provide the preprocessed source file after reading http://gcc.gnu.org/bugs.html.
Comment 2 Robin Daugherty 2003-12-31 14:45:01 UTC
Created attachment 5388 [details]
File With The Warning
Comment 3 Robin Daugherty 2003-12-31 14:50:02 UTC
Created attachment 5389 [details]
File Without The Warning (correct behavior)

When compiled with -Wall, this file will produce "defined but not used"
warnings only for doc, args_doc, and options.  This is correct, because
although bugs_doc and version are not used, they have the __unused__ attribute
set.
Comment 4 Robin Daugherty 2003-12-31 15:07:42 UTC
Created attachment 5390 [details]
MySQL header file
Comment 5 Robin Daugherty 2003-12-31 15:10:07 UTC
I have observed this with 3.2.1 and 3.3.2 (made with default options for x86 on
Linux).  I compile these files with -Wall (I use this option in my Makefiles).

I have attached two files, one which causes five warnings, and one which causes
only three.  The difference between them is that #include <mysql/my_global.h> is
before the definitions in the first file, but after them in the second.

Let me know if you still want preprocessed sources from me.
Comment 6 Falk Hueffner 2003-12-31 15:41:35 UTC
#if !defined(__attribute__) && (defined(__cplusplus) || !defined(__GNUC__)  ||
__GNUC__ == 2 && __GNUC_MINOR__ < 8)
#define __attribute__(A)
#endif

There's the cuplrit. Complain to whoever provided this header file.
Comment 7 Jeremy Zawodny 2004-02-17 23:03:19 UTC
I made sure this got into MySQL AB's bug tracking system:

http://bugs.mysql.com/bug.php?id=2717

Jeremy