[Boost.Filesystem] Is there any bug in ofstream implementation ?

Hi, I not pretty sure but it seems that there is a bug (?) somewhere in boost::filesystem::ofstream implementation in the Boost 1.34.1 release; to exhibit this behaviour, the snippet code hereafter trigger an assert in the last block: int main(int /*argc*/, char* /*argv[]*/) { const fs::path p("c:/temp/test.txt") ; const fs::wpath wp(L"c:/temp/test.txt") ; { fs::remove(p) ; fs::ofstream ofile(p) ; assert(!ofile.fail()) ; } { fs::remove(p) ; fs::ofstream ofile(wp) ; assert(!ofile.fail()) ; } { fs::remove(p) ; fs::ofstream ofile(p, std::ios_base::binary) ; assert(!ofile.fail()) ; } { fs::remove(p) ; fs::ofstream ofile(wp, std::ios_base::binary) ; assert(!ofile.fail()) ; // <-- Assert triggered here } } Running conditions: Boost 1.34.1 Visual C++ 7.1 Windows XP I'm waiting for your feedback. Best regards, Marc VIALA

AMDG Marc Viala Perso wrote:
Hi,
I not pretty sure but it seems that there is a bug (?) somewhere in boost::filesystem::ofstream implementation in the Boost 1.34.1 release; to exhibit this behaviour, the snippet code hereafter trigger an assert in the last block:
int main(int /*argc*/, char* /*argv[]*/) { const fs::path p("c:/temp/test.txt") ; const fs::wpath wp(L"c:/temp/test.txt") ; { fs::remove(p) ; fs::ofstream ofile(p) ; assert(!ofile.fail()) ; } { fs::remove(p) ; fs::ofstream ofile(wp) ; assert(!ofile.fail()) ; }
{ fs::remove(p) ; fs::ofstream ofile(p, std::ios_base::binary) ; assert(!ofile.fail()) ; } { fs::remove(p) ; fs::ofstream ofile(wp, std::ios_base::binary) ; assert(!ofile.fail()) ; // <-- Assert triggered here } }
Running conditions: Boost 1.34.1 Visual C++ 7.1 Windows XP
Does it work with std::ofstream using back-slashes and raw C strings? In Christ, Steven Watanabe

-----Message d'origine----- bounces@lists.boost.org] De la part de Steven Watanabe Envoyé : vendredi 1 février 2008 21:16
int main(int /*argc*/, char* /*argv[]*/) { const fs::path p("c:/temp/test.txt") ; const fs::wpath wp(L"c:/temp/test.txt") ; { fs::remove(p) ; fs::ofstream ofile(p) ; assert(!ofile.fail()) ; } { fs::remove(p) ; fs::ofstream ofile(wp) ; assert(!ofile.fail()) ; }
{ fs::remove(p) ; fs::ofstream ofile(p, std::ios_base::binary) ; assert(!ofile.fail()) ; } { fs::remove(p) ; fs::ofstream ofile(wp, std::ios_base::binary) ; assert(!ofile.fail()) ; // <-- Assert triggered here } }
Running conditions: Boost 1.34.1 VisuIal C++ 7.1 Windows XP
Does it work with std::ofstream using back-slashes and raw C strings?
[Marc Viala] I've replaced slashes by black-slashes in fs::path (p and wp) to confirm the same behaviour: I've got an assert at the same code line. My feeling is that the default opening mode "std::ios_base::out" in conjunction with fs::ofstream is overwritten; for example, if someone replace the last "ofile" declaration with that one: fs::ofstream ofile(wp, std::ios_base::binary| std::ios_base::out) every thing work fine!! Best regards, Marc VIALA
participants (2)
-
Marc Viala Perso
-
Steven Watanabe