From owner-freebsd-ports@freebsd.org Mon Nov 14 14:38:09 2016 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EB69FC4077A; Mon, 14 Nov 2016 14:38:09 +0000 (UTC) (envelope-from gahr@FreeBSD.org) Received: from mail.ptrcrt.ch (gahr.cloud.tilaa.com [84.22.109.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2D50ECBE; Mon, 14 Nov 2016 14:38:08 +0000 (UTC) (envelope-from gahr@FreeBSD.org) Received: from webmail.ptrcrt.ch (www.gahr.ch [192.168.1.2]) by mail.ptrcrt.ch (OpenSMTPD) with ESMTPSA id c4844c57 TLS version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO; Mon, 14 Nov 2016 14:38:05 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Mon, 14 Nov 2016 15:38:05 +0100 From: Pietro Cerutti To: =?UTF-8?Q?Otac=C3=ADlio?= Cc: owner-freebsd-ports@freebsd.org, freebsd-ports@freebsd.org Subject: Re: How compile "String inf = static_cast(&(ostringstream() << pAct.minArea))->str();" Organization: The FreeBSD Project In-Reply-To: References: Message-ID: <31a0dab8289c0a62d8f8b4c041aefdee@FreeBSD.org> X-Sender: gahr@FreeBSD.org User-Agent: Roundcube Webmail/1.2.2 X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Nov 2016 14:38:10 -0000 On 2016-11-14 14:39, Otacílio wrote: > Em 14/11/2016 06:29, Pietro Cerutti escreveu: >> On 2016-11-09 02:37, Otacílio wrote: >>> I'm trying create a patch to OpenCV 3.1 runs on FreeBSD but clang >>> don't compiles lines like this: >>> >>> String inf = static_cast(&(ostringstream() << >>> pAct.minArea))->str(); >> >> There's nothing wrong with this code, provided that: >> >> * is included >> * ostringstream is actually std::ostringstream >> * pAct.minArea defines operator<< to std::ostringstream or one of its >> base classes >> >> What's the error you're getting? >> >> That being said, I'd switch to using c++11 and String inf = >> std::to_string(pAct.minArea) :) >> > > Hi > > This code is in > /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp/detect_mser.cpp > line 76 . I'm using C++11. The full compiler error message is this: > > > [ 95%] Built target example_image_sequence > --- samples/cpp/CMakeFiles/example_select3dobj.dir/all --- > /usr/bin/make -f > samples/cpp/CMakeFiles/example_select3dobj.dir/build.make > samples/cpp/CMakeFiles/example_select3dobj.dir/depend > --- samples/cpp/CMakeFiles/example_select3dobj.dir/depend --- > cd /usr/ports/graphics/opencv3/work/opencv-3.1.0 && > /usr/local/bin/cmake -E cmake_depends "Unix Makefiles" > /usr/ports/graphics/opencv3/work/opencv-3.1.0 > /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp > /usr/ports/graphics/opencv3/work/opencv-3.1.0 > /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp > /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp/CMakeFiles/example_select3dobj.dir/DependInfo.cmake > --color= > --- samples/cpp/CMakeFiles/example_detect_mser.dir/all --- > /usr/ports/graphics/opencv3/work/opencv-3.1.0/samples/cpp/detect_mser.cpp:76:46: > error: cannot take the address of an rvalue of type > 'std::__1::basic_ostringstream, > std::__1::allocator >' > String inf = static_cast(&(ostringstream() << > pAct.minArea))->str(); > ^ > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ oh, of course :) you could force runtime polymorphism by turning the temporary into a reference, like this: String inf = static_cast(ostringstream() << pAct.minArea).str() -- Pietro Cerutti gahr@FreeBSD.org PGP Public Key: http://gahr.ch/pgp