From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14107 invoked by alias); 10 Jan 2002 13:36:03 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 14069 invoked by uid 71); 10 Jan 2002 13:36:02 -0000 Resent-Date: 10 Jan 2002 13:36:02 -0000 Resent-Message-ID: <20020110133602.14067.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, peter@snake.iap.physik.tu-darmstadt.de Received:(qmail 11979 invoked from network); 10 Jan 2002 13:33:06 -0000 Received: from unknown (HELO snake.iap.physik.tu-darmstadt.de) (130.83.4.87) by sources.redhat.com with SMTP; 10 Jan 2002 13:33:06 -0000 Received: (from schmid@localhost) by snake.iap.physik.tu-darmstadt.de (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id OAA13432; Thu, 10 Jan 2002 14:33:05 +0100 Message-Id:<200201101333.OAA13432@snake.iap.physik.tu-darmstadt.de> Date: Thu, 10 Jan 2002 05:36:00 -0000 From: peter@snake.iap.physik.tu-darmstadt.de To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:3.113 Subject: c++/5348: Problems with valarrays (struct members are private) X-SW-Source: 2002-01/txt/msg00409.txt.bz2 List-Id: >Number: 5348 >Category: c++ >Synopsis: Problems with valarrays (struct members are private) >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: rejects-legal >Submitter-Id: net >Arrival-Date: Thu Jan 10 05:36:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: Peter Schmid >Release: 3.1 20020108 (experimental) >Organization: TU Darmstadt >Environment: System: Linux kiste 2.4.17 #7 Thu Jan 3 17:21:51 CET 2002 i686 unknown Architecture: i686 linux 2.4.17 glibc 2.2.4 + patches GNU ld version 2.11.92.0.12.3 20011121 host: i686-pc-linux-gnu build: i686-pc-linux-gnu target: i686-pc-linux-gnu configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads --enable-languages=c,c++,f77,objc >Description: Valarrays do not compile on the mainline. That is because of a compiler bug. The compiler treats the members of the _BinClos<_Oper,_ValArray,_Constant,_Tp,_Tp> struct as private in contrast to the standard. If this struct is written as a class with a public label gcc accepts tv2.C without a warning. >How-To-Repeat: source code tv2.C namespace std { #define size_t unsigned long template struct binary_function { typedef _Arg1 first_argument_type; typedef _Arg2 second_argument_type; typedef _Result result_type; }; template struct plus : public binary_function<_Tp,_Tp,_Tp> { _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } }; template class _Expr; template class _ValArray; template class _Oper, template class _Meta, class _Dom> struct _UnClos; template class _Oper, template class _Meta1, template class _Meta2, class _Dom1, class _Dom2> class _BinClos; template struct _Unary_plus; template class valarray; // An array of type _Tp template struct _Array {}; template class _Constant; template class _Oper, class _Clos> class _BinBase2 { public: typedef typename _Clos::value_type _Vt; typedef _Oper<_Vt> _Op; typedef typename _Op::result_type value_type; _BinBase2 (const _Clos& __e, const _Vt& __t) : _M_expr1 (__e), _M_expr2 (__t) {} value_type operator[] (size_t) const; size_t size () const { return _M_expr1.size (); } private: const _Clos& _M_expr1; const _Vt& _M_expr2; }; template class _Oper, class _Clos> inline typename _BinBase2<_Oper,_Clos>::value_type _BinBase2<_Oper,_Clos>::operator[] (size_t __i) const { return _Op() (_M_expr1[__i], _M_expr2); } template class _Oper, typename _Tp> struct _BinClos<_Oper,_ValArray,_Constant,_Tp,_Tp> : _BinBase2<_Oper,valarray<_Tp> > { typedef _BinBase2<_Oper,valarray<_Tp> > _Base; typedef typename _Base::value_type value_type; _BinClos (const valarray<_Tp>& __v, const _Tp& __t) : _Base (__v, __t) {} }; template class _Expr { public: _Expr (const _Clos&); }; template class valarray { public: typedef _Tp value_type; valarray(); explicit valarray(size_t); template valarray(const _Expr<_Dom,_Tp>& __e); }; #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \ \ template \ inline _Expr<_BinClos<_Name,_ValArray,_Constant,_Tp,_Tp>,_Tp> \ operator _Op (const valarray<_Tp> &__v, const _Tp &__t) \ { \ typedef _BinClos<_Name,_ValArray,_Constant,_Tp,_Tp> _Closure; \ return _Expr<_Closure, _Tp> (_Closure (__v, __t)); \ } \ _DEFINE_BINARY_OPERATOR(+, plus) #undef _DEFINE_BINARY_OPERATOR } // namespace std using namespace std; int main() { valarray va(9); valarray vb(va+10.0); } g++ -v tv2.C -W -Wall --save-temps Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/specs Configured with: ../gcc/configure --enable-shared --disable-nls --enable-threads --enable-languages=c,c++,f77,objc Thread model: posix gcc version 3.1 20020108 (experimental) /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/cpp0 -lang-c++ -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -v -D__GNUC__=3 -D__GNUC_MINOR__=1 -D__GNUC_PATCHLEVEL__=0 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -W -Wall -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ tv2.C tv2.ii GNU CPP version 3.1 20020108 (experimental) (cpplib) (i386 Linux/ELF) ignoring nonexistent directory "NONE/include" ignoring nonexistent directory "/usr/local/i686-pc-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include/g++-v3 /usr/local/include/g++-v3/i686-pc-linux-gnu /usr/local/include/g++-v3/backward /usr/local/include /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/include /usr/include End of search list. /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.1/cc1plus -fpreprocessed tv2.ii -quiet -dumpbase tv2.C -W -Wall -version -o tv2.s GNU CPP version 3.1 20020108 (experimental) (cpplib) (i386 Linux/ELF) GNU C++ version 3.1 20020108 (experimental) (i686-pc-linux-gnu) compiled by GNU C version 3.1 20020108 (experimental). tv2.C: In function `int main()': tv2.C:104: warning: unused variable `std::valarray vb' tv2.C: In function `std::_Expr, _Tp> std::operator+(const std::valarray<_Tp>&, const _Tp&) [with _Tp = double]': tv2.C:104: instantiated from here tv2.C:65: `std::_BinClos<_Oper, std::_ValArray, std::_Constant, _Tp, _Tp>::_BinClos(const std::valarray<_Tp>&, const _Tp&) [with _Oper = std::plus, _Tp = double]' is private tv2.C:93: within this context preprocessed source code tv2.ii # 1 "tv2.C" # 1 "" # 1 "" # 1 "tv2.C" namespace std { template struct binary_function { typedef _Arg1 first_argument_type; typedef _Arg2 second_argument_type; typedef _Result result_type; }; template struct plus : public binary_function<_Tp,_Tp,_Tp> { _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } }; template class _Expr; template class _ValArray; template class _Oper, template class _Meta, class _Dom> struct _UnClos; template class _Oper, template class _Meta1, template class _Meta2, class _Dom1, class _Dom2> class _BinClos; template struct _Unary_plus; template class valarray; template struct _Array {}; template class _Constant; template class _Oper, class _Clos> class _BinBase2 { public: typedef typename _Clos::value_type _Vt; typedef _Oper<_Vt> _Op; typedef typename _Op::result_type value_type; _BinBase2 (const _Clos& __e, const _Vt& __t) : _M_expr1 (__e), _M_expr2 (__t) {} value_type operator[] (unsigned long) const; unsigned long size () const { return _M_expr1.size (); } private: const _Clos& _M_expr1; const _Vt& _M_expr2; }; template class _Oper, class _Clos> inline typename _BinBase2<_Oper,_Clos>::value_type _BinBase2<_Oper,_Clos>::operator[] (unsigned long __i) const { return _Op() (_M_expr1[__i], _M_expr2); } template class _Oper, typename _Tp> struct _BinClos<_Oper,_ValArray,_Constant,_Tp,_Tp> : _BinBase2<_Oper,valarray<_Tp> > { typedef _BinBase2<_Oper,valarray<_Tp> > _Base; typedef typename _Base::value_type value_type; _BinClos (const valarray<_Tp>& __v, const _Tp& __t) : _Base (__v, __t) {} }; template class _Expr { public: _Expr (const _Clos&); }; template class valarray { public: typedef _Tp value_type; valarray(); explicit valarray(unsigned long); template valarray(const _Expr<_Dom,_Tp>& __e); }; # 93 "tv2.C" template inline _Expr<_BinClos,_Tp> operator + (const valarray<_Tp> &__v, const _Tp &__t) { typedef _BinClos _Closure; return _Expr<_Closure, _Tp> (_Closure (__v, __t)); } } using namespace std; int main() { valarray va(9); valarray vb(va+10.0); } >Fix: >Release-Note: >Audit-Trail: >Unformatted: