This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

__attribute__ ((no_check_memory_usage)) in template member functions?


I'm using gcc (g++ actually) 2.95.2 running on Linux on a Pentium II (x86).  I
have a test program, and I want to compile it with -fcheck-memory-usage.  My
program uses strings (#include <string>).  When gcc gets around to compiling a
source file with strings, it says this:

g++ -g -c -Wall -ansi -pedantic -fcheck-memory-usage -fprefix-function-name
-fstack-check  -O3 -DNDEBUG -I. -I../include -I../src/settingsdb -D_GNU_SOURCE
-D_REENTRANT -DPLATFORM_LINUX=1 -DDEBUGGING_IN_TEST_HARNESS=1 -DEXPORT=
-D_PTHREADS ../src/settingtree/testCAttribute.cpp -o testCAttribute.o
In file included from ../src/settingtree/testCAttribute.cpp:78:
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/std/bastring.h:
In method `void
basic_string<char,string_char_traits<char>,__default_alloc_template<true,0>
>::Rep::release()':
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/std/bastring.h:172:  
instantiated from
`basic_string<char,string_char_traits<char>,__default_alloc_template<true,0>
>::operator =(const basic_string<char,string_char_traits<char>,__default_alloc_template<true,0> > &)'
../include/Attribute.h:124:   instantiated from here
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/std/bastring.h:91:
`asm' cannot be used with `-fcheck-memory-usage'

Looking in std/bastring.h:

template <class charT, class traits = string_char_traits<charT>,
	  class Allocator = alloc >
class basic_string
{
private:
  struct Rep {
    size_t len, res, ref;
    bool selfish;

    charT* data () { return reinterpret_cast<charT *>(this + 1); }
    charT& operator[] (size_t s) { return data () [s]; }
    charT* grab () { if (selfish) return clone (); ++ref; return data (); }
#if defined __i486__ || defined __i586__ || defined __i686__
	void release ()
      {
	size_t __val;
	// This opcode exists as a .byte instead of as a mnemonic for the
	// benefit of SCO OpenServer 5.  The system assembler (which is 
	// essentially required on this target) can't assemble xaddl in 
	//COFF mode.
	asm (".byte 0xf0, 0x0f, 0xc1, 0x02" // lock; xaddl %eax, (%edx)
	    : "=a" (__val)
	    : "0" (-1), "m" (ref), "d" (&ref)
	    : "memory");

	if (__val == 1)
	  delete this;
      }

OK...I think I know what to do:

	void release () __attribute__ ((no_check_memory_usage))
	{
		...

Nope:

g++ -g -c -Wall -ansi -pedantic -fcheck-memory-usage -fprefix-function-name
-fstack-check  -O3 -DNDEBUG -I. -I../include -I../src/settingsdb -D_GNU_SOURCE
-D_REENTRANT -DPLATFORM_LINUX=1 -DDEBUGGING_IN_TEST_HARNESS=1 -DEXPORT=
-D_PTHREADS ../src/settingtree/testCAttribute.cpp -o testCAttribute.o
In file included from
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/string:6,
                 from ../include/Attribute.h:53,
                 from ../src/settingtree/testCAttribute.cpp:78:
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/std/bastring.h:80:
parse error before `{'

How about this?

	void release () __attribute__ ((no_check_memory_usage));

	void release ()
	{
		...

Nope:

g++ -g -c -Wall -ansi -pedantic -fcheck-memory-usage -fprefix-function-name
-fstack-check  -O3 -DNDEBUG -I. -I../include -I../src/settingsdb -D_GNU_SOURCE
-D_REENTRANT -DPLATFORM_LINUX=1 -DDEBUGGING_IN_TEST_HARNESS=1 -DEXPORT=
-D_PTHREADS ../src/settingtree/testCAttribute.cpp -o testCAttribute.o
In file included from ../src/settingtree/testCAttribute.cpp:78:
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/std/bastring.h:
In instantiation of
`basic_string<char,string_char_traits<char>,__default_alloc_template<true,0>
>::Rep':
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/std/bastring.cc:518:  
instantiated from
`basic_string<char,string_char_traits<char>,__default_alloc_template<true,0>
>'
../include/Attribute.h:130:   instantiated from here
/usr/lib/gcc-lib/i586-mandrake-linux/2.95.2/../../../../include/g++-3/std/bastring.h:82:
`basic_string<char,string_char_traits<char>,__default_alloc_template<true,0>
>::Rep::release()' has already been declared in `basic_string<char,string_char_traits<char>,__default_alloc_template<true,0> >::Rep'

Can someone tell me either:

	1) How do I declare an attribute for a template function?

		or

	2) How do I move the weird-looking asm() to a separate
	   function in a separate file where I can declare it with
	   __attribute__ ((no_check_memory_usage))?

Thanks.

--
George T. Talbot
<george@moberg.com>

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]