diff options
author | Mark Mitchell <mark@markmitchell.com> | 1999-02-26 12:15:37 +0000 |
---|---|---|
committer | Mark Mitchell <mmitchel@gcc.gnu.org> | 1999-02-26 12:15:37 +0000 |
commit | 5f56af5a8d207f088d752e59d855e27a8f39b579 (patch) | |
tree | c074f48d1b17289aa9732bf7361a00bee2f585b9 /gcc | |
parent | 2b0a63a35b58c529363c6ed6db01f26d9cfa737f (diff) | |
download | gcc-5f56af5a8d207f088d752e59d855e27a8f39b579.zip gcc-5f56af5a8d207f088d752e59d855e27a8f39b579.tar.gz gcc-5f56af5a8d207f088d752e59d855e27a8f39b579.tar.bz2 |
typeck.c (decay_conversion): Don't confuse constant array variables with their intiailizers.
* typeck.c (decay_conversion): Don't confuse constant array
variables with their intiailizers.
From-SVN: r25459
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 24 | ||||
-rw-r--r-- | gcc/testsuite/g++.old-deja/g++.other/string1.C | 20 |
3 files changed, 37 insertions, 10 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4424a32..34e8ef8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,8 @@ 1999-02-26 Mark Mitchell <mark@markmitchell.com> + * typeck.c (decay_conversion): Don't confuse constant array + variables with their intiailizers. + * decl.c (duplicate_decls): Copy DECL_TEMPLATE_INSTANTIATED when merging decls. * pt.c (regenerate_decl_from_template): Tweak for clarity. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 426d02b..9a99097 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1589,12 +1589,11 @@ c_alignof (type) return t; } -/* Perform default promotions for C data used in expressions. - Arrays and functions are converted to pointers; - enumeral types or short or char, to int. - In addition, manifest constants symbols are replaced by their values. +/* Perform the array-to-pointer and function-to-pointer conversions + for EXP. - C++: this will automatically bash references to their target type. */ + In addition, references are converted to rvalues and manifest + constants are replaced by their values. */ tree decay_conversion (exp) @@ -1628,8 +1627,15 @@ decay_conversion (exp) /* Constants can be used directly unless they're not loadable. */ if (TREE_CODE (exp) == CONST_DECL) exp = DECL_INITIAL (exp); - /* Replace a nonvolatile const static variable with its value. */ - else if (TREE_READONLY_DECL_P (exp)) + /* Replace a nonvolatile const static variable with its value. We + don't do this for arrays, though; we want the address of the + first element of the array, not the address of the first element + of its initializing constant. We *do* replace variables that the + user isn't really supposed to know about; this is a hack to deal + with __PRETTY_FUNCTION__ and the like. */ + else if (TREE_READONLY_DECL_P (exp) + && (code != ARRAY_TYPE + || (TREE_CODE (exp) == VAR_DECL && DECL_IGNORED_P (exp)))) { exp = decl_constant_value (exp); type = TREE_TYPE (exp); @@ -1649,9 +1655,7 @@ decay_conversion (exp) return build_unary_op (ADDR_EXPR, exp, 0); } if (code == FUNCTION_TYPE || is_overloaded_fn (exp)) - { - return build_unary_op (ADDR_EXPR, exp, 0); - } + return build_unary_op (ADDR_EXPR, exp, 0); if (code == ARRAY_TYPE) { register tree adr; diff --git a/gcc/testsuite/g++.old-deja/g++.other/string1.C b/gcc/testsuite/g++.old-deja/g++.other/string1.C new file mode 100644 index 0000000..425e9bf --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.other/string1.C @@ -0,0 +1,20 @@ +// Build don't link: +// Origin: mrs@wrs.com (Mike Stump) + +class Wrapper { +public: + static const char msgPtr[]; + static const char *JunkFunc() { + return &msgPtr[0]; + } +}; + +const char Wrapper::msgPtr[] = "Hello world."; + +int main() { + const char *p1 = &Wrapper::msgPtr[0]; + const char *p2 = Wrapper::JunkFunc(); + + if (p1 != p2) + return 1; +} |