C++ Code formatting for templates auto-adds weird default value
-
When I format the follwoing line of code as C++:
template
and post the messge, afterwards that line is auto-magically changed to
template
It doesn't happen every time, so I'm not sure what causes it. But there are plenty of postings in the C++ forum and Q&A that show the unwanted
=""
addition!GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
-
When I format the follwoing line of code as C++:
template
and post the messge, afterwards that line is auto-magically changed to
template
It doesn't happen every time, so I'm not sure what causes it. But there are plenty of postings in the C++ forum and Q&A that show the unwanted
=""
addition!GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
It could be that the system thinks that
<class T>
is an HTML element and that theT
is an attribute, resulting in this change. If that's the issue, then a way to solve this is to change the<
and>
chars into their HTML Entities,<
and>
The quick red ProgramFOX jumps right over the
Lazy<Dog>
. My latest article: Create an HTML5 (and JavaScript) Maze Game with a timer My group: C# Programmers Group -
It could be that the system thinks that
<class T>
is an HTML element and that theT
is an attribute, resulting in this change. If that's the issue, then a way to solve this is to change the<
and>
chars into their HTML Entities,<
and>
The quick red ProgramFOX jumps right over the
Lazy<Dog>
. My latest article: Create an HTML5 (and JavaScript) Maze Game with a timer My group: C# Programmers GroupSeems like just writing
template
and then enclosing it in
pre
tags doesn't provoke the error immediately, must be some intermediate step. But yes, now that you mention it,#include
commands using angular brackets also get eaten by HTML. Must be connected to that.GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
-
When I format the follwoing line of code as C++:
template
and post the messge, afterwards that line is auto-magically changed to
template
It doesn't happen every time, so I'm not sure what causes it. But there are plenty of postings in the C++ forum and Q&A that show the unwanted
=""
addition!GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
If you post just "template <class T>" then yes, the message process will consider is s HTML and will attempt to "fix" it. If you wrap it in <PRE> tags then it won't. If you want to be able to post stuff that has <'s in it without the message system thinking it's HTML then check the "Treat my content as plain text, not as HTML" checkbox in the Options section just above the "Post Message" button at the bottom.
cheers Chris Maunder
-
If you post just "template <class T>" then yes, the message process will consider is s HTML and will attempt to "fix" it. If you wrap it in <PRE> tags then it won't. If you want to be able to post stuff that has <'s in it without the message system thinking it's HTML then check the "Treat my content as plain text, not as HTML" checkbox in the Options section just above the "Post Message" button at the bottom.
cheers Chris Maunder
I have seen this happen even if it is in pre tags. There is also the auto-tag-close thing that also happens in pre tags. Neither of these always happens, but the do happen.
What do you get when you cross a joke with a rhetorical question?
-
I have seen this happen even if it is in pre tags. There is also the auto-tag-close thing that also happens in pre tags. Neither of these always happens, but the do happen.
What do you get when you cross a joke with a rhetorical question?
Brisingr Aerowing wrote:
I have seen this happen even if it is in pre tags.
Which is exactly what I was complaining about - if I enclose something with <pre lang="c++">...</pre>, then I want it formatted as code, not HTML. Enclosing it in text tags instead defeats the purpose.
Brisingr Aerowing wrote:
There is also the auto-tag-close thing that also happens in pre tags.
Yup. When HTML finds anything that it thinks are tags - even though the text is enclosed in pre tags! - then it will swallow those presumed tags, and also auto-add closing tags at the end. This is rather annoying when you try to format code containing #include directives or template arguments! I've written many solutions and answers containing such code and now am used to use the > and < HTML tags within the code rather than using < and >, but the problem is that even a small typo can break code, and due to the HTML eating bits of code it's often impossible to just copy & paste the actual code - you have to modify it!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
-
Brisingr Aerowing wrote:
I have seen this happen even if it is in pre tags.
Which is exactly what I was complaining about - if I enclose something with <pre lang="c++">...</pre>, then I want it formatted as code, not HTML. Enclosing it in text tags instead defeats the purpose.
Brisingr Aerowing wrote:
There is also the auto-tag-close thing that also happens in pre tags.
Yup. When HTML finds anything that it thinks are tags - even though the text is enclosed in pre tags! - then it will swallow those presumed tags, and also auto-add closing tags at the end. This is rather annoying when you try to format code containing #include directives or template arguments! I've written many solutions and answers containing such code and now am used to use the > and < HTML tags within the code rather than using < and >, but the problem is that even a small typo can break code, and due to the HTML eating bits of code it's often impossible to just copy & paste the actual code - you have to modify it!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
Stefan_Lang wrote:
When HTML finds anything that it thinks are tags - even though the text is enclosed in pre tags!
What's meant to happen is that all HTML tags within PRE blocks except for I,U and B get auto-encoded so the processor doesn't see them as HTML anymore. Clearly Possibly a bug. I'll dig in and see what's happening. [Edit] However, I can't replicate the issue at this point Test:
#include
cheers Chris Maunder
-
Stefan_Lang wrote:
When HTML finds anything that it thinks are tags - even though the text is enclosed in pre tags!
What's meant to happen is that all HTML tags within PRE blocks except for I,U and B get auto-encoded so the processor doesn't see them as HTML anymore. Clearly Possibly a bug. I'll dig in and see what's happening. [Edit] However, I can't replicate the issue at this point Test:
#include
cheers Chris Maunder
trying to reproduce... Test: copy paste from text editor, click elsewhere (auto-closes 'Paste-as' dialog), then select and enclose in <pre>
#include
template
class myT {
T var;
};Test 2: copy from within unsent post, including pre tags
#include
template
class myT {
T var;
};Test 3: copy from within unsent post, excluding pre tags, use paste as code
#include <string>
template <class T>
class myT {
T var;
};Edit: ok, all seems to work, except pasting as codeblock uses C# formatting by default. Also the C# formatting automatically replaced the < and > tokens with the corresponding HTML tags automatically. Another test: typing (not copying) same code, then enclose in pre
#include
template
class myT {
var T;
};At this point I'm running out of ideas - maybe it's only in some forums ? I've noticed it in Q&A, will go test there... Edit 2: Tried 'improving' a solution of mine in Q&A, but couldn't reproduce the issue. I'll bookmark this thread and come back when i find an example that can be reproduced. Edit 3: Another test, trying to reproduce the problem i just faced in Q&A:
template
class myT {
T var;
public:
void hello();
};
void foo() {
myT x;
x.hello();
}The function
myT::hello()
.GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
-
Stefan_Lang wrote:
When HTML finds anything that it thinks are tags - even though the text is enclosed in pre tags!
What's meant to happen is that all HTML tags within PRE blocks except for I,U and B get auto-encoded so the processor doesn't see them as HTML anymore. Clearly Possibly a bug. I'll dig in and see what's happening. [Edit] However, I can't replicate the issue at this point Test:
#include
cheers Chris Maunder
It seems to happen randomly. I never know when it will hit.
/// /// Adds all to .
///
public static void AddRange(this ICollection list, IEnumerable elements)
{
foreach (T o in elements)
list.Add(o);
}template function_declaration;
template function_declaration;//This example throws the following error : call of overloaded 'max(double, double)' is ambiguous
template
Type max(Type a, Type b) {
return a > b ? a : b;
}What do you get when you cross a joke with a rhetorical question?
-
It seems to happen randomly. I never know when it will hit.
/// /// Adds all to .
///
public static void AddRange(this ICollection list, IEnumerable elements)
{
foreach (T o in elements)
list.Add(o);
}template function_declaration;
template function_declaration;//This example throws the following error : call of overloaded 'max(double, double)' is ambiguous
template
Type max(Type a, Type b) {
return a > b ? a : b;
}What do you get when you cross a joke with a rhetorical question?
Let me know when you can replicate it.
cheers Chris Maunder
-
Let me know when you can replicate it.
cheers Chris Maunder
Can't exactly replicate, but in my last attempt got different errors, trying to post this:
template
class myT {
T var;
public:
void hello();
};
void foo() {
myT x;
x.hello();
}The function
myT::hello()
.GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
-
Let me know when you can replicate it.
cheers Chris Maunder
In my recent reply (I deliberately did not edit it), the last case of <int> has been eaten by HTML - although it's actually still in the original text!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto) Point in case: http://www.infoq.com/news/2014/02/apple_gotofail_lessons[^]
-
Let me know when you can replicate it.
cheers Chris Maunder
Here's another formatting issue for C++ code: a triple slash followed by anything containing either a 'less' sign or the associated html tag, leads to the remainder of the code being greyed out! Not even sure why any parts of C++ code should be greyed out!? Interestingly, the part before the less sign is correctly formatted in green, as a comment, although the leading triple slash is still grey :confused: Here's an example:
void foo() {
/// some < meaningful code
some = more + code;
}GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
Let me know when you can replicate it.
cheers Chris Maunder
And another occurence, this time concerning
dynamic_cast
template arguments. In the solution I posted here[^], I tried to post code containingdynamic_cast<some_type*>(some_pointer);
but what I got - even after an attempt to correct it - was
dynamic_cast(some_pointer);
I needed to replace the < and > tokens by the corresponding HTML tags to fix it! Test to replicate:
dynamic_cast(some_pointer)
P.S.: Test failed - couldn't replicate :(
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)