Gcc Error Attributes Are Not Allowed On A Function-definition
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Preventing gcc from inlining a function [duplicate] up vote 5 down vote favorite This question already has an answer here: How can I tell gcc not to inline a function? 6 answers Is it possible to prevent the gcc compiler from inlining a particular function. If so, how? Don't tell me to reduce the optimization level. I want all optimizations on, but mark a particular function to no be inlined by the compiler, just like volatile in case of variables. And the reason I want to do this is because my function uses inline assembly defined labels, which gcc messes up when it inlines the function, as inlining causes gcc to create multiple instances of that label. c linux gcc x86 share|improve this question edited Nov 2 '11 at 11:32 asked Nov 2 '11 at 11:26 MetallicPriest 8,9561280186 marked as duplicate by Ciro Santilli 烏坎事件2016六四事件 法轮功, fedorquilinux Users with the linux badge can single-handedly close linux questions as duplicates and reopen them as needed. May 12 '15 at 9:16 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. Please explain your problem more precisely. Multiple instances of a label? This should never happen. Which version of gcc is giving you that? You are sure that you only have the function defined in one and single compilation unit? –Jens Gustedt Nov 2 '11 at 11:39 @Jens, the reason why this happens is that inlined functions are placed directly inside the code, so if you have an inline assembly defined label inside that funtion, the c
User account creation filtered due to spam. Bug12246 - __attribute__ not allowed in member function definition Summary: __attribute__ not allowed in member function definition Status: RESOLVED FIXED Alias: None Product: gcc Classification: Unclassified Component: c++ (show other bugs) Version: 3.2.3 Importance: P2 enhancement Target Milestone: 3.4.0 Assignee: Not yet assigned to anyone URL: Keywords: diagnostic Depends on: Blocks: Reported: 2003-09-11 07:00 UTC by Bruce Fitzsimons Modified: 2004-01-01 01:42 UTC (History) CC List: 1 user (show) gcc-bugs See Also: Host: Target: Build: http://stackoverflow.com/questions/7979561/preventing-gcc-from-inlining-a-function Known to work: Known to fail: Last reconfirmed: 2003-09-11 14:06:28 Attachments Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description Bruce Fitzsimons 2003-09-11 07:00:34 UTC __attribute__ attributes are not able to be placed on inline ctors, which is a bit frustrating. Sometimes inline ctors are used https://gcc.gnu.org/bugzilla/show_bug.cgi?id=12246 in header files, esp. when doing a thin layer of inheritance around an existing object ie only the base class needs initialisation, there are no new member variables. This is often the case for deriving exceptions, where a new type is desired (for specific catch'es) but no new methods or members are defined. A simple example (not the inheritance case) class A { public: A(int _anInt) __attribute__ ((deprecated)) { anInt = _anInt; } private: int anInt; }; int main(void) { A aInstance(42); } Fails to parse: g++ test.cc test.cc:4: syntax error before `{' token test.cc:5: semicolon missing after declaration of `A' test.cc: In function `int main()': test.cc:10: no matching function for call to `A::A(int)' test.cc:2: candidates are: A::A(const A&) Comment 1 Bruce Fitzsimons 2003-09-11 07:02:56 UTC I can provide a more realistic example, if required, or attach the test.cc if copy/paste from the bug text is unacceptable. Comment 2 Wolfgang Bangerth 2003-09-11 14:06:27 UTC Indeed, but this has nothing to do with constructors, as this example shows: ------------------------------------------------------ struct A { int f() __attribute__ ((deprecated)) {} }; int f() __attribute__ ((deprecated)) {
email llvm-admin@lists.llvm.org if you need an account. First Last Prev Next This bug is not in your last search results. Bug7339 - Function attribute position Summary: https://llvm.org/bugs/show_bug.cgi?id=7339 Function attribute position Status: NEW Product: clang Classification: Unclassified Component: Frontend Version: trunk Platform: PC Windows XP Importance: P normal Assigned To: Unassigned Clang Bugs URL: Keywords: Depends on: Blocks: Show dependency tree /graph Reported: 2010-06-09 19:52 CDT by John Thompson Modified: 2010-08-05 16:58 CDT (History) CC List: 2 users (show) efriedma llvm-bugs See Also: Attachments Repo (77 bytes, text/plain) 2010-06-22 18:57 CDT, John gcc error Thompson Details Add an attachment (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description John Thompson 2010-06-09 19:52:17 CDT file.cpp:70474:13: warning: attribute declaration must precede definition extern bool func(const void *pPtr) __attribute__((__const__)); gcc seems to allow attributes at the end of the function declaration: ^ http://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Function-Attributes.html#Function-Attributes Comment 1 John Thompson 2010-06-09 20:06:42 CDT gcc error attributes Actually, I guess it's because __const__ is not a supported attribute. Should it be? The warning probably should indicate this too. Comment 2 Eli Friedman 2010-06-09 21:08:18 CDT IIRC, the warning actually means that there was a previous definition of the function in question, so the attribute is going to be ignored. Perhaps the wording could be improved. Comment 3 John Thompson 2010-06-10 14:10:25 CDT I see. Yes, there is an inline that is seen later. However, if I add the same attribute to the inline, then I get a different error: C:\Sony\Clang\exp>clang -cc1 attrpos.cpp attrpos.cpp:1:74: error: invalid token after top level declarator inline void isUncachedMemory(const void *pPtr) __attribute__((__const__)) {} ^ ; 1 error generated. The code: inline void isUncachedMemory(const void *pPtr) __attribute__((__const__)) {} Comment 4 John Thompson 2010-06-22 18:57:12 CDT Created attachment 5091 [details] Repo Comment 5 John Thompson 2010-08-05 16:58:04 CDT Actually gcc doesn't like the repo case, saying "attributes are not allowed on a function-definition", so I guess this is not a bug, just how things are. The real case is: inline void isUncachedMemory() {} extern void isUncachedMemory() __attribute__((__const__)) ; Which makes sense. In playing around with work-arounds, I added a declaration before