[aspectc-user] Can't compile with a function that takes an argument of string object

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Fri Jul 4 10:08:41 CEST 2003


Hello Herry,

Herry Leonard wrote:
> Hi all,
> 
> I create a simple function with a string object as its argument. The parsing is working 
> fine, but during compilation with g++, I get bunch of errors.
> 
> Btw, I am using aspectc++ version 0.7 (01.07.2003) and g++ version 2.96 in Red Hat 
> Linux 7.2 box.
> 
> I attached the sample program below:
> 
> [main.cpp]
> 
> #include <string>
> #include <stdio.h>
> 
> class MyClass
> {
>     public:
>         void MethodA(const string&);
> };
> 
> void MyClass::MethodA(const string& s1)
> {
>     printf("I'm in MethodA\n");
> }
> 
> int main()
> {
>     MyClass myClass;
>     myClass.MethodA("test");
>     return 0;
> }
> 
> 
> [Action.ah]
> 
> #include <stdio.h>
> 
> aspect Action {
>   advice execution("% MyClass::%(...)") || execution("% MyClass(...)") : void before()  {
>     printf("before execution\n");
>   }
>   advice execution("% MyClass::%(...)") || execution("% MyClass(...)") : void after()  {
>     printf("after execution\n");
>   }
> };
> 
> 
> During g++ compilation of aspectc++-generated codes, I got there errors:
> g++  -o action main.cpp ac_gen.cpp
> main.cpp:14: syntax error before `%'
> main.cpp:14: nondigits in number and not hexadecimal
> main.cpp:14: nondigits in number and not hexadecimal
> main.cpp:14: nondigits in number and not hexadecimal
> main.cpp:14: missing white space after number `12basi'
> main.cpp:20: syntax error before `%'
> main.cpp:20: nondigits in number and not hexadecimal
> main.cpp:20: nondigits in number and not hexadecimal
> main.cpp:20: nondigits in number and not hexadecimal
> main.cpp:20: missing white space after number `12basi'
> main.cpp:30: wrong number of template arguments (0, should be 3)
> /usr/include/g++-3/std/bastring.h:67: provided for `template <charT,
> traits, Allocator> class basic_string'
> main.cpp:31: ISO C++ forbids declaration of `arg0' with no type
> main.cpp:31: prototype for `void MyClass::MethodA (const int &)' does
> not match any in class `MyClass'
> main.cpp:9: candidate is: void MyClass::MethodA (const string &)
> main.cpp: In method `void MyClass::MethodA (const int &)':
> main.cpp:32: `a0_before_Action_exec_MyClassMethodA_FN7MyClassEvRKN15'
> undeclared (first use this function)
> main.cpp:32: (Each undeclared identifier is reported only once for each
> function it appears in.)
> main.cpp:32: nondigits in number and not hexadecimal
> main.cpp:32: nondigits in number and not hexadecimal
> main.cpp:32: nondigits in number and not hexadecimal
> main.cpp:32: missing white space after number `12basi'
> main.cpp:32: wrong number of template arguments (0, should be 3)
> /usr/include/g++-3/std/bastring.h:67: provided for `template <charT,
> traits, Allocator> class basic_string'
> main.cpp:32: parse error before `12basi'
> main.cpp:33: no matching function for call to `MyClass::__old_MethodA
> (const int &)'
> main.cpp:27: candidates are: void MyClass::__old_MethodA (const string
> &)
> main.cpp:34: `a1_after_Action_exec_MyClassMethodA_FN7MyClassEvRKN15'
> undeclared (first use this function)
> main.cpp:34: nondigits in number and not hexadecimal
> main.cpp:34: nondigits in number and not hexadecimal
> main.cpp:34: nondigits in number and not hexadecimal
> main.cpp:34: missing white space after number `12basi'
> main.cpp:34: wrong number of template arguments (0, should be 3)
> /usr/include/g++-3/std/bastring.h:67: provided for `template <charT,
> traits, Allocator> class basic_string'
> main.cpp:34: parse error before `12basi'
> make: *** [action] Error 1
> 
> 
> Is there anything wrong in my codes above? Could we use string as the argument for a 
> function? Btw, if I use string object inside function only, it works fine.
> 
> Thanks.
> 
> Regards,
> Herry Leonard

there are three problems with your code:

1. execution("% MyClass(...)")
    Do you want to match a constructor with this expression? Matching
    constructor calls or execution is still not supported by ac++.
    With this expression ac++ tries to match a (non-member) function
    called MyClass, which does not exist.

2. void before()
    declaring advice as 'void' is obsolete, simply use
    advice ... : before() { ... }

3. void MethodA(const string&);
    the 'string' argument causes code generation problems. This this a
    bug. The bugzilla number is 112. Half of the bug is already fixed and
    I hope that the rest of the work will be done today. We consider this
    problem to be important. Thus, we will provide a 0.7fix1 as soon as
    possible (first we will have a look into your latest report on the
    std::... problem).

Yours,

Olaf





More information about the aspectc-user mailing list