public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: peter@snake.iap.physik.tu-darmstadt.de To: gcc-gnats@gcc.gnu.org Subject: c++/5348: Problems with valarrays (struct members are private) Date: Thu, 10 Jan 2002 05:36:00 -0000 [thread overview] Message-ID: <200201101333.OAA13432@snake.iap.physik.tu-darmstadt.de> (raw) >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 <class _Arg1, class _Arg2, class _Result> struct binary_function { typedef _Arg1 first_argument_type; typedef _Arg2 second_argument_type; typedef _Result result_type; }; template <class _Tp> struct plus : public binary_function<_Tp,_Tp,_Tp> { _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } }; template<class _Clos, typename _Tp> class _Expr; template<typename _Tp1, typename _Tp2> class _ValArray; template<template<class> class _Oper, template<class, class> class _Meta, class _Dom> struct _UnClos; template<template<class> class _Oper, template<class, class> class _Meta1, template<class, class> class _Meta2, class _Dom1, class _Dom2> class _BinClos; template<class _Tp> struct _Unary_plus; template<class _Tp> class valarray; // An array of type _Tp template<typename _Tp> struct _Array {}; template<typename _Tp1, typename _Tp2> class _Constant; template<template<class> 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<template<class> 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<template<class> 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 _Clos, typename _Tp> class _Expr { public: _Expr (const _Clos&); }; template<class _Tp> class valarray { public: typedef _Tp value_type; valarray(); explicit valarray(size_t); template<class _Dom> valarray(const _Expr<_Dom,_Tp>& __e); }; #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \ \ template<typename _Tp> \ 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<double> va(9); valarray<double> 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<double> vb' tv2.C: In function `std::_Expr<std::_BinClos<std::plus, std::_ValArray, std::_Constant, _Tp, _Tp>, _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 "<built-in>" # 1 "<command line>" # 1 "tv2.C" namespace std { template <class _Arg1, class _Arg2, class _Result> struct binary_function { typedef _Arg1 first_argument_type; typedef _Arg2 second_argument_type; typedef _Result result_type; }; template <class _Tp> struct plus : public binary_function<_Tp,_Tp,_Tp> { _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; } }; template<class _Clos, typename _Tp> class _Expr; template<typename _Tp1, typename _Tp2> class _ValArray; template<template<class> class _Oper, template<class, class> class _Meta, class _Dom> struct _UnClos; template<template<class> class _Oper, template<class, class> class _Meta1, template<class, class> class _Meta2, class _Dom1, class _Dom2> class _BinClos; template<class _Tp> struct _Unary_plus; template<class _Tp> class valarray; template<typename _Tp> struct _Array {}; template<typename _Tp1, typename _Tp2> class _Constant; template<template<class> 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<template<class> 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<template<class> 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 _Clos, typename _Tp> class _Expr { public: _Expr (const _Clos&); }; template<class _Tp> class valarray { public: typedef _Tp value_type; valarray(); explicit valarray(unsigned long); template<class _Dom> valarray(const _Expr<_Dom,_Tp>& __e); }; # 93 "tv2.C" template<typename _Tp> inline _Expr<_BinClos<plus,_ValArray,_Constant,_Tp,_Tp>,_Tp> operator + (const valarray<_Tp> &__v, const _Tp &__t) { typedef _BinClos<plus,_ValArray,_Constant,_Tp,_Tp> _Closure; return _Expr<_Closure, _Tp> (_Closure (__v, __t)); } } using namespace std; int main() { valarray<double> va(9); valarray<double> vb(va+10.0); } >Fix: >Release-Note: >Audit-Trail: >Unformatted:
next reply other threads:[~2002-01-10 13:36 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-01-10 5:36 peter [this message] 2002-01-11 14:16 Paolo Carlini 2002-01-17 15:03 bkoz 2002-01-18 1:46 Nathan Sidwell 2002-01-19 12:56 nathan
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=200201101333.OAA13432@snake.iap.physik.tu-darmstadt.de \ --to=peter@snake.iap.physik.tu-darmstadt.de \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).