From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14610 invoked by alias); 19 Dec 2012 15:54:38 -0000 Received: (qmail 14534 invoked by uid 48); 19 Dec 2012 15:54:23 -0000 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55737] Template and the constant, short-form if-then-else condition issue Date: Wed, 19 Dec 2012 15:54:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-12/txt/msg01892.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55737 --- Comment #3 from Jonathan Wakely 2012-12-19 15:54:22 UTC --- (Your testcase would be a lot easier to read without all those comments inside the conditional expression, I think it's safe to assume everyone here knows which is the false branch of a conditional expression!) A conditional expression is not a "static if" so templates in both branches of the conditional expression are instantiated, and instantiating DivByX<0> fails. You could work around this by preventing instantiation of the problem case, the simplest way is to specialize the template: template <> struct DivByX<0> { enum { value1 = X, value2 = 0; }; }; Now it doesn't matter if the DivByX<0> case is instantiated because it doesn't divide by zero.