Boost C++ Libraries: Ticket #4146: [patch] ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:117: error: non-constant `(((int)f_c) | 3072)' cannot be used as template argument https://svn.boost.org/trac10/ticket/4146 <p> When compiling today's development trunk of boost, I see the following errors: </p> <pre class="wiki">[snip] gcc.compile.c++ bin.v2/libs/graph/build/gcc-3.4.4/release/threading-multi/graphml.o ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp: In function `void boost::property_tree::xml_parser::read_xml_internal(std::basic_istream&lt;typename Ptree::key_type::value_type, std::char_traits&lt;typename Ptree::key_type::value_type&gt; &gt;&amp;, Ptree&amp;, int, const std::string&amp;) [with Ptree = boost::property_tree::basic_ptree&lt;std::string, std::string, std::less&lt;std::string&gt; &gt;]': ./boost/property_tree/xml_parser.hpp:52: instantiated from `void boost::property_tree::xml_parser::read_xml(std::basic_istream&lt;typename Ptree::key_type::value_type, std::char_traits&lt;typename Ptree::key_type::value_type&gt; &gt;&amp;, Ptree&amp;, int) [with Ptree = boost::property_tree::ptree]' libs\graph\src\graphml.cpp:49: instantiated from here ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:117: error: non-constant `(((int)f_c) | 3072)' cannot be used as template argument ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:117: error: no matching function for call to `boost::property_tree::detail::rapidxml::xml_document&lt;char&gt;::parse(char*)' [snip] </pre><p> bjam was generated in the follwing way: </p> <pre class="wiki">$ ./bootstrap.sh --prefix=$HOME/local --exec-prefix=$HOME/local/${MACHTYPE=i686-pc-cygwin} </pre><p> It is compiled on Windows XP machine, under a recent update of Cygwin. </p> <pre class="wiki">$ g++ --version g++ (GCC) 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </pre><p> I googled up a workaround (ref. <code>&lt;http://old.nabble.com/Sandia-gcc-3.4.6-error-on-Boost.Graph-td26800239.html&gt;</code>) that fixes the problem for me, see attached <code>svn diff</code>. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4146 Trac 1.4.3 Jan-Hein Bührman <buhrman@…> Sat, 24 Apr 2010 16:33:42 GMT attachment set https://svn.boost.org/trac10/ticket/4146 https://svn.boost.org/trac10/ticket/4146 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost-property_tree_fix2.diff</span> </li> </ul> Ticket Jan-Hein Bührman <buhrman@…> Mon, 26 Apr 2010 09:20:38 GMT summary changed https://svn.boost.org/trac10/ticket/4146#comment:1 https://svn.boost.org/trac10/ticket/4146#comment:1 <ul> <li><strong>summary</strong> <span class="trac-field-old">./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:117: error: non-constant `(((int)f_c) | 3072)' cannot be used as template argument</span> → <span class="trac-field-new">[patch] ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:117: error: non-constant `(((int)f_c) | 3072)' cannot be used as template argument</span> </li> </ul> Ticket Sebastian Redl Tue, 27 Apr 2010 08:59:36 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4146#comment:2 https://svn.boost.org/trac10/ticket/4146#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/61605" title="Cater to compilers too stupid to interpret a bitwise OR in a template ...">[61605]</a>) Cater to compilers too stupid to interpret a bitwise OR in a template argument as a constant. </p> <p> Fixes bug 4146 </p> Ticket anonymous Sun, 08 Aug 2010 11:10:03 GMT <link>https://svn.boost.org/trac10/ticket/4146#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:3</guid> <description> <p> Looks like this patch didn't make it into release 1.43.0. :( </p> </description> <category>Ticket</category> </item> <item> <author>Leonid Gershanovich <gleonid@…></author> <pubDate>Sun, 20 Mar 2011 18:05:03 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/4146 https://svn.boost.org/trac10/ticket/4146 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">xml_parser_read_rapidxml.hpp.patch_1_46_0</span> </li> </ul> <p> using enums instead of const int template arguments </p> Ticket Leonid Gershanovich <gleonid@…> Sun, 20 Mar 2011 18:14:11 GMT <link>https://svn.boost.org/trac10/ticket/4146#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:4</guid> <description> <p> please consider previous attachments. essentially I propose to use enums instead of const int: </p> <pre class="wiki"> -- const int f_tws = parse_normalize_whitespace -- | parse_trim_whitespace; + enum { f_tws = parse_normalize_whitespace + | parse_trim_whitespace }; </pre><p> This should work with any compiler as <strong>enum</strong> is a compile time constant, while <strong>const int</strong> is a run time constant. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sebastian Redl</dc:creator> <pubDate>Sun, 20 Mar 2011 19:26:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:5</guid> <description> <p> Do you have a specific incredibly broken compiler that you want me to support with that? </p> </description> <category>Ticket</category> </item> <item> <author>Leonid Gershanovich <gleonid@…></author> <pubDate>Mon, 21 Mar 2011 15:10:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:6</guid> <description> <p> gcc 3.4.6 (RHEL 4) and gcc 4.1.2 (RHEL 5) both choking on this construct. </p> </description> <category>Ticket</category> </item> <item> <author>buhrman@…</author> <pubDate>Mon, 21 Mar 2011 15:38:04 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4146#comment:6" title="Comment 6">Leonid Gershanovich &lt;gleonid@…&gt;</a>: </p> <blockquote class="citation"> <p> gcc 3.4.6 (RHEL 4) and gcc 4.1.2 (RHEL 5) both choking on this construct. </p> </blockquote> <p> Just to get things clear and to prevent mistakes: are these <code>gcc</code> versions <span class="wikianchor" id="point1">(1)</span> choking on the original sources where I provided a patch for, or <span class="wikianchor" id="point2">(2)</span> <em>after</em> you have applied this patch (<a class="ext-link" href="https://svn.boost.org/trac/boost/attachment/ticket/4146/boost-property_tree_fix2.diff"><span class="icon">​</span>boost-property_tree_fix2.diff</a>)? </p> <p> In the first case <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4146#point1" title="#4146: Bugs: [patch] ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:117: ... (closed: fixed)">(1)</a> I would would recommend just moving to a more recent version of Boost, because despite the remark made in <a class="ticket" href="https://svn.boost.org/trac10/ticket/4146#comment:3" title="Comment 3">comment 3 by anonymous</a> I believe the fix is now in the latest release(s). </p> <p> In the latter case <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4146#point2" title="#4146: Bugs: [patch] ./boost/property_tree/detail/xml_parser_read_rapidxml.hpp:117: ... (closed: fixed)">(2)</a> this would mean that <code>gcc</code> got worse (or more picky - I don't know since I'm not a C++ standard expert) since the proposed patch did solve the problem for <code>gcc 3.4.4</code>. </p> </description> <category>Ticket</category> </item> <item> <author>Leonid Gershanovich <gleonid@…></author> <pubDate>Mon, 21 Mar 2011 16:03:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:8</guid> <description> <p> I am using boost <strong>1.46.1</strong>. </p> <p> Those gcc versions are chocking on "const int" used as template argument, since "const int" is not a compile time constant in a strict sense. </p> </description> <category>Ticket</category> </item> <item> <author>buhrman@…</author> <pubDate>Mon, 21 Mar 2011 19:53:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:9</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4146#comment:8" title="Comment 8">Leonid Gershanovich &lt;gleonid@…&gt;</a>: </p> <blockquote class="citation"> <p> I am using boost <strong>1.46.1</strong>. </p> <p> Those gcc versions are chocking on "const int" used as template argument, since "const int" is not a compile time constant in a strict sense. </p> </blockquote> <p> Stroustrup, <em>The C++ Programming Language</em>, 3rd ed., 3rd printing, sect. 13.2.3, <em>Template Parameters</em>, states: </p> <blockquote> <p> A template argument can be a constant expression (sect. C.5). </p> </blockquote> <p> And sect. C.5, <em>Constant Expressions</em>, states: </p> <blockquote> <p> A constant expression evaluates to an integral or enumeration constant. Such an expression is composed of literals [...], enumerators [...], and <em>const</em>s initialized by constant expressions. </p> </blockquote> <p> I didn't check the official standard, but I guess, reading the above, any decent compiler should grok this. </p> </description> <category>Ticket</category> </item> <item> <author>Leonid Gershanovich <gleonid@…></author> <pubDate>Mon, 21 Mar 2011 20:58:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:10</guid> <description> <p> As I already mentioned above there is a difference between run time and compile time constants. Other than that you are right: "const int" is a constant. </p> <p> However I was not looking to open a discussion about c++ standard. </p> <p> Is there a reason why you believe that enum should not be used in this particular case? </p> <p> In any case - please let me know if you decide to dismiss my suggestion, in which case I'll keep applying patch to local copy of your library every time boost releases new version. </p> <p> Thanks </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sebastian Redl</dc:creator> <pubDate>Tue, 22 Mar 2011 09:23:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:11</guid> <description> <p> buhrman is completely right. These const ints are compile-time constants, and any compiler that doesn't treat them as such is broken. </p> <p> That said, my only objection to your patch is that I find enums to define non-enumerated constants to be extremely ugly, and local enums even more so. That said, I'll see about applying your patch. </p> <p> It's strange, though. According to the trunk test matrix, gcc-3.4.6 works just fine (the Sandia gcc-3.4.6 tester is all green). Furthermore, 4.0.1, 4.2.1, 4.2.4, 4.3.4, 4.4.3, 4.4.4, 4.4.5, 4.5.1 and 4.5.2 all work fine. The release branch XML test also passes for every single GCC version tested. </p> </description> <category>Ticket</category> </item> <item> <author>Jan-Hein Bührman <buhrman@…></author> <pubDate>Tue, 22 Mar 2011 09:49:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4146#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4146#comment:12</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4146#comment:11" title="Comment 11">cornedbee</a>: </p> <blockquote class="citation"> <p> [...] It's strange, though. According to the trunk test matrix, gcc-3.4.6 works just fine (the Sandia gcc-3.4.6 tester is all green). Furthermore, 4.0.1, 4.2.1, 4.2.4, 4.3.4, 4.4.3, 4.4.4, 4.4.5, 4.5.1 and 4.5.2 all work fine. The release branch XML test also passes for every single GCC version tested. </p> </blockquote> <p> This would make me very curious about the <strong>exact</strong> compiler diagnostic issued. </p> <p> Since this is a <em>different</em> problem (though very similar), with a (must be) <em>different</em> compiler diagnostic, with <em>different</em> (newer) versions of Boost and <code>gcc</code>, I would like to suggest that a new ticket is opened with the new compiler diagnostic, version identifications, etc. </p> <p> This makes it also easier for others having the same problem to find the right solution. </p> <p> [This was my last €0,02 - I'm bailing out of this discussion now] </p> </description> <category>Ticket</category> </item> </channel> </rss>