This is the mail archive of the gcc-patches@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]
Other format: [Raw text]

g++ patch to fix handling of cfstrings in function templates


Following test case uses a cfstring inside a function template. Program bus errors.

We build the following const_decl for a cfstring in objective-c++ front-end:

/* NeXT: (NSConstantString *) & ((__builtin_ObjCString) { isa, string, length }) */

This is represented as a ADDR_EXPR of a CONST_DECL node whose DECL_INITIAL field holds the CONSTRUCTOR initializer. This tree is inside the function template. At instantiation time, pt.c replaces above tree with ADDR_EXPR of CONSTRUCTOR node which is wrong. This simple patch fixes this bug. Is this OK for FSF main line? Dejagnu tested on apple-ppc-darwin with no regressions.

- Fariborz

Test.

#import <Foundation/Foundation.h>

template <typename T> class getter
{
public:
    NSString* foo ( T* obj )
    {
        return @"target2";
    }
};

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    getter<NSObject> g;
    NSLog ( @"String = [%@]", g.foo ( nil ) );
    [pool release];
    return 0;
}

patch.

Index: pt.c
===================================================================
*** pt.c        (revision 114050)
--- pt.c        (working copy)
*************** tsubst_copy_and_build (tree t,
*** 8738,8743 ****
--- 8738,8746 ----
        if (TREE_CODE (op1) == SCOPE_REF)
        op1 = tsubst_qualified_id (op1, args, complain, in_decl,
                                   /*done=*/true, /*address_p=*/true);
+       else if (TREE_CODE (op1) == CONST_DECL
+              && TREE_CODE (DECL_INITIAL (op1)) == CONSTRUCTOR)
+       ;
        else
        op1 = tsubst_non_call_postfix_expression (op1, args, complain,
                                                  in_decl);

cp/ChangeLog

2006-05-25 Fariborz Jahanian <fjahanian@apple.com>

cfstring inside a function template.
* pt.c (tsubst_copy_and_build): Don't fold ADDR_EXPR of a COST_DECL
with CONSTRUCTOR initializer.




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